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
)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章