ATTENTION this question is about Go language specs not best practice or recommendation.
I have read many articles of packages but I still don't quite understand the relationship of directory and package name. Here is my example.
My project structure is like the following screenshots. When I do go run ~/go/src/myproj/main.go
the error says:
src\myproj\main.go:5:2: cannot find package "myproj/pa/pb" in any of: c:\go\src\myproj\pa\pb (from $GOROOT) C:\Users\terry\go\src\myproj\pa\pb (from $GOPATH)
However if I change package pb
to package pa
in p.go, and change the import from "myproj/pa/pb"
to "myproj/pa"
, and change fmt.Print(pb.Greet)
to fmt.Print(pa.Greet)
in main.go, it will work. Does the inner most directory must match the package declaration name? My go version is 1.14.4