GO module的正确用法
参考:https://go.dev/blog/using-go-modules
go mod init
creates a new module, initializing thego.mod
file that describes it.go build
,go test
, and other package-building commands add new dependencies togo.mod
as needed.go list -m all
prints the current module’s dependencies.go get
changes the required version of a dependency (or adds a new dependency).go mod tidy
removes unused dependencies.
注意go get的主要作用是修改依赖的module的版本,go get xxxx 时,其实等价于go get xxx@latest,使之本项目需要依赖最新版本的xxx模块,而通过go get xxx @version 来指定版本,不只是下载指定版本的模块,还可以改变go.mod中的依赖项的版本。