First of all The project structure I want to achieve is to have a separate directory to store third-party open source libraries, and then my own multiple golang projects can share these open source libraries.
In addition, I don’t want to set the global gopath directory every time I switch projects. Implementation methodFirst set the environment variables
vi ~/.bash_profile
Only set the shared third-party open source library storage directory here, and the third-party libraries installed by go get will be stored here
export GOPATH=/work/go/gopath
In When compiling the project, manually add the project and directory after GOPATH
echo $GOPATH
export GOPATH=$ GOPATH:/work/go/loolgameecho $GOPATH
/work/go/gopath:/work/go/loolgame
The project directory must be shared After the open source directoryFinally execute the compilation command
go install server
How to set it under the compiler
intelij IDEA Configuration environmentCompile go get golang.org/x/net Installation failure solution
Installation command: go get golang.org/x/net, error message: package golang.org/x/net: unrecognized import path "golang.org/x/net", package document address: https://godoc.org/golang.org/....
This problem is mainly because golang.org is blocked and cannot be accessedThe simple solution is
Download from https://github.com/golang/net, and then change the directory to golang .org/x/net. Then, everything is fine.
ps: If you have git, you can directly go get github.com/golang/net. If not, you can download it manually and put it in the src directory.