英文:
Cannot install private Go module
问题
我有一个私有项目,使用了位于github.com/company/company-product的私有模块。当我尝试构建项目时,我遇到了以下错误:
go: github.com/company/company-product@v1.0.4: 在版本v1.0.4上读取github.com/company/company-product/go.mod时出错:未知的版本v1.0.4
我尝试过的方法有:
- 检查标签是否存在
- 运行
go env -w GO111MODULE=on - 运行
go env -w GOPRIVATE=github.com/company/company-product - 运行
export GOPRIVATE=github.com/company/* - 运行
export GONOPROXY=github.com/company/* - 运行
export GONOSUMDB=github.com/company/* - 配置git使用
ssh://git@github.com/而不是https://github.com/ - 配置git使用
ssh://$PERSONAL_ACCESS_TOKEN@github.com/而不是https://github.com/ - 删除
$GOPATH/pkg目录下的所有内容 - 运行
go clean - 运行
go mod download、go mod tidy、go mod vendor(所有这些命令都会产生上述错误) - 重启电脑
- 连接到我的公司的VPN
然而,我仍然遇到相同的错误。
英文:
I have a private project which uses a private module at github.com/company/company-product. When I try to build the project, I get:
go: github.com/company/company-product@v1.0.4: reading github.com/company/company-product/go.mod at revision v1.0.4: unknown revision v1.0.4
Things I have tried:
- Checked that the tag exists
go env -w GO111MODULE=ongo env -w GOPRIVATE=github.com/company/company-productexport GOPRIVATE=github.com/company/*export GONOPROXY=github.com/company/*export GONOSUMDB=github.com/company/*- Configured git to use
ssh://git@github.com/instead ofhttps://github.com/ - Configured git to use
ssh://$PERSONAL_ACCESS_TOKEN@github.com/instead ofhttps://github.com/ - Deleted everything in
$GOPATH/pkg go cleango mod download,go mod tidy,go mod vendor(which all produce the above error)- Restarted my computer
- Connected to my company's VPN
And yet I still get the same error.
答案1
得分: 3
看起来关键是按照特定的顺序进行操作:
- 重新安装 Go
- 设置环境变量 GOPRIVATE、GONOPROSXY 和 GONOSUMDB 为
github.com/company/* - 删除文件夹
$GOPATH/pkg - 配置 Git 使用
ssh://git@github.com/而不是https://github.com/ - 运行
go get github.com/company/company-product
英文:
It looks like the key was to do things in a certain order:
- Reinstall Go
- Set environment variables GOPRIVATE, GONOPROSXY, GONOSUMDB to
github.com/company/* - Remove the folder
$GOPATH/pkg - Setup Git to use
ssh://git@github.com/instead ofhttps://github.com/ - Run
go get github.com/company/company-product
答案2
得分: 0
以下是为我工作的解决方案:
- 运行命令
go env -w GOPRIVATE=github.com/company - 运行命令
git config --global url."https://username:accesstoken@github.com".insteadOf "https://github.com" - 运行命令
env GIT_TERMINAL_PROMPT=1 go get github.com/company/privaterepo
英文:
the solution which worked for me;
- go env -w GOPRIVATE=github.com/company
- git config --global url."https://username:accesstoken@github.com".insteadOf "https://github.com"
- env GIT_TERMINAL_PROMPT=1 go get github.com/company/privaterepo
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论