import "/astaxie/beego" Compilation error solution:
go get
Make sure your GOPATH is the project directory, the code is in the src directory, and then enter: go get /astaxie/beego in the command prompt.
Then, the external package to be introduced is generated under the local src.
Notice:
When using the GoLand tool, configure settings->Go->GOPATH->Project GOPATH as the current project directory.
go module
Go Module can only be used above version 1.11, and Go Module below version 1.13 is turned off by default.
First, you need to set the environment variable set GO111MODULE=on,
In the GOPATH directory, create a new project folder, enter the new path and execute go mod init, and generate a file in the folder.
Then place the go file that needs to be introduced into the external package in the project directory. After compiling the file, the external package will be downloaded to the local GOPATH/pkg/mod directory.
Notice:
When using GoLand tools, do not configure Project GOPATH as the current project directory. It is best not to configure Project GOPATH, but to configure Module GOPATH
vendor directory
First install govendor: go get -u -v /kardianos/govendor
After downloading, configure the environment variable GOPATH/bin, type the command govendor -version to check whether the installation is successful
In the directory of GOPATH/src, create a new project folder, enter the new path and execute gogovendor init, and vendor/ will be generated in the folder.
Then place the go file that needs to be introduced into the external package in the project directory.
Use the command:
govendor fetch /golang/glog Download external files to local vendor/ and add information about the dependency package in it. Where govendor fetch adds dependency package from the remote library and adds dependency package from $GOPATH, using govendor add
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.