The go language package is very similar to the package in Java, both in the way the code is organized and in relation to the directory structure on disk.
In the go language, the package name is generally the directory name of the go code, but unlike Java, the package name is only one level in the go language, while in Java the package name is a multi-level catalog with points split.
In the go language, it is necessary to refer to the package with the GOPATH/SRC directory as the relative root directory, and then enter the following directory names at each level.
Example: Environment variable Gopath = ~/go
Package Hello has hello.go, the disk path where the package is located is:
~/go/src/golang_everyday/hello
In other words, the path to Hello.go is:
~/go/src/golang_everyday/hello/hello.go
When you reference the go file in another file, the code should be:
Import "Golang_everyday/hello"
If there are multiple Gopath, the go will be searched next to each gopath SRC until it is found.
Main is a special package name, similar to the Java main function, go executable program must be under the main packages, the main folder is not usually called main.
In the same package, multiple files are treated as a file by the go compiler, so the same global variables and functions cannot appear in multiple files, one exception being the init function, and the different files of the same package can refer to each other directly.
Go Language Pack and package reference