[Golang] 解決 Go 1.13 之後下載私有倉庫專案錯誤(410 Gone)
錯誤訊息
把Go升級到1.13之後
在某次重新下載依賴的package
突然出現以下錯誤
go get private.com/package/name
go: finding private.com/package/name latest
go: downloading private.com/package/name v0.0.0-20191114175342-81c79a005368
verifying private.com/package/[email protected]: private.com/package/[email protected]: reading https://sum.golang.org/lookup/private.com/package/[email protected]: 410 Gone
導致原因
當下覺得超奇怪
還以為是我的repo掛了
搜尋後發現
原來是Go 1.13 之後會預設 GOPROXY 為 proxy.golang.org
導致私有專案無法檢查checksum
然後下載失敗
可參考官方說明
The GOPROXY environment variable may now be set to a comma-separated list of proxy URLs or the special token direct, and its default value is now https://proxy.golang.org,direct. When resolving a package path to its containing module, the go command will try all candidate module paths on each proxy in the list in succession. An unreachable proxy or HTTP status code other than 404 or 410 terminates the search without consulting the remaining proxies.
解決方法
在官方說明中
Go 1.13 加入了一個新的環境變數
叫 GOPRIVATE,以下是介紹
The new GOPRIVATE environment variable indicates module paths that are not publicly available. It serves as the default value for the lower-level GONOPROXY and GONOSUMDB variables, which provide finer-grained control over which modules are fetched via proxy and verified using the checksum database.
原來設置這個參數之後
在這範圍內的package都會用原本的行為GONOPROXY 跟 GONOSUMDB
這樣就不會通過GOPROXY下載
也就不會有checksum的問題了
設定範例
export GOPRIVATE="private.com,private2.com"
留言