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 initInitialize project dependencies and generate go.mod files
go mod downloadDownload dependencies according to the go.mod file
go mod tidyCompare the dependencies introduced in the project file with go.mod
go mod graphoutput dependency graph
go mod editEdit the go.mod file
go mod vendorExport all dependencies of the project to the vendor directory
go mod verifyCheck if a dependent package has been tampered with
go mod whyexplain why a dependency is needed
go module introduction

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:

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish