golang 配置私有仓库

  • 配置使用ssh 访问的仓库

 

1. go mod 根据go.mod拉取依赖库时,会使用https的方式。为了方便我们也可以通过配置git 全局配置来使用 ssh的方式拉取依赖,下面是配置 https转换为ssh的方式:

git config --global url."[email protected]:".insteadOf "https://gitee.com/"

2. 配置环境变量,来指定私有仓库,用于不走代理的方式

go env -w GOPRIVATE=gitee.com

这里配置私有仓库是gitee

3. 设置代理

go env -w GOPROXY=goproyx.io

 

常见错误:

1. 错误一

abc@Genricde helloworld % go get -u gitee.com/abc/helloworld/v3 go: gitee.com/abc/helloworld/[email protected] requires gitee.com/abc/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /Users/abc/developer/golang/pkg/mod/cache/vcs/742008abb4987f237c93efc5ddde7db6dd8d1841fe94aea076046d86a92e26a7: exit status 128: fatal: could not read Username for 'https://gitee.com': terminal prompts disabled

 

这种错误为没有配置 git 的https转换为 ssh

 

2. 错误二

go: gitee.com/abc/[email protected] requires gitee.com/abc/[email protected]/go.mod: verifying module: gitee.com/abc/[email protected]/go.mod: reading https://goproxy.io/sumdb/sum.golang.org/lookup/gitee.com/abc/[email protected]: 410 Gone server response: not found: gitee.com/abc/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/742008abb4987f237c93efc5ddde7db6dd8d1841fe94aea076046d86a92e26a7: exit status 128: fatal: could not read Username for 'https://gitee.com': terminal prompts disabled

 

这种错误是GOPRIVATE 设置错误,使得go去验证库的sum

你可能感兴趣的:(golang)