- 配置使用ssh 访问的仓库
1. go mod 根据go.mod拉取依赖库时,会使用https的方式。为了方便我们也可以通过配置git 全局配置来使用 ssh的方式拉取依赖,下面是配置 https转换为ssh的方式:
git config --global url."git@gitee.com:".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/v3@v3.0.1-5 requires gitee.com/abc/tsab@v0.0.0-20210208082057-adbeb3ca5366: 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/helloworld@v0.0.0-20210121064045-46ac6dd9cdce requires gitee.com/abc/helloworld@v0.0.0-20210208023819-88ebb8c504ae/go.mod: verifying module: gitee.com/abc/helloworld@v0.0.0-20210208023819-88ebb8c504ae/go.mod: reading https://goproxy.io/sumdb/sum.golang.org/lookup/gitee.com/abc/tsab@v0.0.0-20210208023819-88ebb8c504ae: 410 Gone server response: not found: gitee.com/abc/helloworld@v0.0.0-20210208023819-88ebb8c504ae: 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