go module introduction
Go module is a dependency management solution released in Go1.11. It is recommended to be used in production environments starting from Go1.14, and it is enabled by default in Go1.16. The Go module provides the following commands for us to use:
go module related commands
go mod init | Initialize project dependencies and generate go.mod files |
go mod download | Download dependencies according to the go.mod file |
go mod tidy | Compare the dependencies introduced in the project file with go.mod |
go mod graph | output dependency graph |
go mod edit | Edit the go.mod file |
go mod vendor | Export all dependencies of the project to the vendor directory |
go mod verify | Check if a dependent package has been tampered with |
go mod why | explain why a dependency is needed |
GOPROXY
This environment variable is mainly used to set the Go module proxy (Go module proxy), and its function is to enable Go to break away from the traditional VCS method when pulling the module version later, and directly pull it quickly through the mirror site.
The default value of GOPROXY is: https://proxy.golang.org,direct. Due to some reasons, this address cannot be accessed normally in China, so we usually need to configure an accessible address. At present, there are two https://goproxy.cn and https://goproxy.io that are widely used in the community. Of course, if your company provides a GOPROXY address, then use it directly. The command to set GOPAROXY is as follows: