GO module的正确用法

参考:https://go.dev/blog/using-go-modules

  • go mod init creates a new module, initializing the go.mod file that describes it.
  • go buildgo 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 getchanges 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中的依赖项的版本。

posted @ 2022-07-22 18:38  morein2008  阅读(39)  评论(0编辑  收藏  举报