vendor
使用vendor進行包管理,首先要保證項目在$GOPATH/src/路徑下(踩過坑),然后build時就會按照如圖所示的優先級進行包的搜索。

一個沒有找到包的實例:

module
- 主要步驟
1. 打開 Go modules
go env -w GO111MODULE=on
2. 設置 GOPROXY
go env -w GOPROXY=https://goproxy.cn,direct
3. 創建項目,生成go.mod文件
go mod init demo
4. go build
4.1 項目中增加了go.sum,編譯好的可執行文件
4.2 go.mod文件內容發生了變化,增加了
require github.com/gin-gonic/gin v最新版本
5. 更換依賴版本
go mod edit -require="github.com/gin-gonic/gin@新版本號(即tags)"
go tidy #更新現有依賴
- go mod init
- go mod
go mod 的 require 和 replace // 附錄3
- 使用 replace 將遠程包替換為本地包服務
Go Module 引入本地自定義包
go mod 私有倉庫 // 附錄4
配置.netrc
其他
- 一個查看go項目的全部依賴(不包括標准庫)的shell命令
A useful terminal command usinggo listto list (non-standard) dependencies in your package directory
go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
深入
// 附錄2
參考資料
1.How make go import packages from vendor?
2.Go Modules 和 Go Proxy
3.Go Modules 內部分享
4.Go Module 常見問題- 私有倉庫
