Happy Coding
使用Go Modules

Go Modules使用着感觉不错,Go终于有正常点的依赖管理工具了。记录一二。

使用小结

  1. go.mod, go.sum加入版本管理 Both go.mod and go.sum should be checked into version control.
  2. 直接依赖体现在go.mod,间接依赖由直接依赖自己管理,这是个递归的过程 Only direct dependencies are recorded in the go.mod file.
  3. go命令自动管理go.mod,这可太方便了 When it encounters an import of a package not provided by any module in go.mod, the go command automatically looks up the module containing that package and adds it to go.mod, using the latest version.
  4. 看着比之前的依赖管理好用很多。比如dep。因为网络下载包等问题,最后把依赖包全checkin到vendor目录了。太臃肿。

常用命令

  • go mod init creates a new module, initializing the go.mod file that describes it.
  • go build, go test, and other package-building commands add new dependencies to go.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.

代理

国内网络的问题,加上下面这行就好很多了。

# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io

Last modified on 2020-02-28