为什么我的client.go无法访问math.go?

  1. Why is my math.go file not found in client.go ?
  2. Is package main the right package for client.go ? If I do package bar it complaints.

enter image description hereenter image description here

Instead of importing ../foo/math you want to import ../foo because you're importing the folder aka the package. There is no folder named math.

If you import ../foo you can use the exported features of all the files within that folder.

As for part two of your question, there needs to be a package main if you are producing an executable, usually I keep my main go file in the root directory instead in a folder. If you are simply making a library than instead of main the package name is the name of the folder (package) as per usual.

If you have a lot of folders no one will be able to find the main function if it's in a folder called bar.