Let's look at an example:
1. Directory structure
Bin
Pkg
Src
Pk1
Pk2
Function1.go
Function2.go
Index.go
2. function1.go File Contents:
Package Pk3func Function_test3 () {println ("Function_test3")}
3. function2.go File Contents:
Package Pk3func Function_test4 () {println ("Function_test4")}
4. index.go File Contents
Package Mainimport "Pk1/pk2" Func Main () {pk3. Function_test4 ()}
5, run Index.go, output:
Function_test4
The following conclusions are drawn:
1. Import imported parameters are paths , not package names .
2, although the habit of the package name and directory name to ensure consistency, but this is not mandatory provisions;
3. When referencing a package member in code, use the package name rather than the directory name ;
4, in the same directory, all source files must use the same package name (because the import uses absolute path, so under the search path, the package must have a unique path, but not necessarily a unique name);
Go-Path, directory name, package name, file name