Demo/x/a/a.gopackage Math //In the X/A directory does not adopt the default directory with the same name of the package name is also possible, so that the reference is to test the directory path, the invocation is the code file declared in the package name Func Add (x, y int) int {return x + y}////////////////////////////////demo/y/a/a.gopackage Math//Two different paths define the same package name Func Mul (x, y int) int {Retu RN x * y}////////////////////////////////demo/main.gopackage Mainimport (//You can assign an alias to the code package under this path, regardless of the package name used in the code, You can also avoid the problem of package name collisions under different paths "./x/a"//import is actually the directory path of the code file, but a path can have many code files, but the code files must all be under the same package Mathx "./y/a" "FMT") func main () { By default the last level directory name and the code file declaration of the package name are the same//this is intentionally declared as different in the test out the call is actually not the last level directory name but the code file declaration of the package name FMT. Println (Math. ADD (2, 3))//Use the specified alias to invoke the function within the package, FMT. Println (mathx. Mul (2, 3)) }
Go language learning-referencing paths and packages