golang 配置私有仓库

  • 配置使用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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值