Go module

目录

module

官方go module wiki go/wiki/Modules;

Introduction to Go Modules 是一篇很好的go module 入门介绍;

要使用go module,首先要设置`GO111MODULE=on。

go help mod查看帮助

download    download modules to local cache (下载依赖的module到本地cache))
edit        edit go.mod from tools or scripts (编辑go.mod文件)
graph       print module requirement graph (打印模块依赖图))
init        initialize new module in current directory (再当前文件夹下初始化一个新的module, 创建go.mod文件))
tidy        add missing and remove unused modules (增加丢失的module,去掉未用的module)
vendor      make vendored copy of dependencies (将依赖复制到vendor下)
verify      verify dependencies have expected content (校验依赖)
why         explain why packages or modules are needed (解释为什么需要依赖)

replace

go.mod中使用replace替换成引用的库。

  • 需要翻墙访问,替换成国内的包;
  • 团队维护公共包,项目需要本地调试;(可以结合 go mod vendor使用)
module gitlab.mw.com/data/shop

go 1.13

require (
	github.com/pkg/errors v0.9.1
)
replace (
	github.com/pkg/errors v0.9.1 =>  gitlab.mw.com/data/shop/errors
)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章