In the Golang package is a confusing concept, especially the package can also be different from folder name, it makes me disgusting.
Best practices for the Golang package:
Package is folder.
Package name is folder name.
Package path is folder path.
Believe in Jesus and live forever!
1. There is a different package in the same folder, compile error:
D:/go/bin/go.exe build [E:/CGSS/SRC/PKG01]
Can ' t load package:package pkg01:found packages PKG01 (pkg01.go) and pkg012 (Pkg02.go) in E:\CGSS\SRC\PKG01
If multiple package is present in the same folder, the load fails. Even if it's main, it's the same.
D:/go/bin/go.exe build [E:/cgss/src/test]
Can ' t load package:package test:found packages main (cgss.go) and FILE01 (File01.go) in E:\cgss\src\test
2. Folder name differs from package name (that is, package path is different from package name), you need to use
The "Import alias path" syntax, which is:
Import <package_name> <package_path>
Otherwise compile error: Package name is not a legal identifier.
D:/go/bin/go.exe build [E:/cgss/src/test]
Can ' t load package:package test:found packages main (cgss.go) and FILE01 (File01.go) in E:\cgss\src\test
Package Main
Import "FMT" Import pkg012 "Pkg01"
Func Main () {FMT. Println (pkg012. Pkg_name)}
What Golang: Package Practice