无法安装私有的Go模块。

huangapple go评论87阅读模式
英文:

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 downloadgo mod tidygo 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=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/*
  • Configured git to use ssh://git@github.com/ instead of https://github.com/
  • Configured git to use ssh://$PERSONAL_ACCESS_TOKEN@github.com/ instead of https://github.com/
  • Deleted everything in $GOPATH/pkg
  • go clean
  • go 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

看起来关键是按照特定的顺序进行操作:

  1. 重新安装 Go
  2. 设置环境变量 GOPRIVATE、GONOPROSXY 和 GONOSUMDB 为 github.com/company/*
  3. 删除文件夹 $GOPATH/pkg
  4. 配置 Git 使用 ssh://git@github.com/ 而不是 https://github.com/
  5. 运行 go get github.com/company/company-product
英文:

It looks like the key was to do things in a certain order:

  1. Reinstall Go
  2. Set environment variables GOPRIVATE, GONOPROSXY, GONOSUMDB to github.com/company/*
  3. Remove the folder $GOPATH/pkg
  4. Setup Git to use ssh://git@github.com/ instead of https://github.com/
  5. Run go get github.com/company/company-product

答案2

得分: 0

以下是为我工作的解决方案:

  1. 运行命令 go env -w GOPRIVATE=github.com/company
  2. 运行命令 git config --global url."https://username:accesstoken@github.com".insteadOf "https://github.com"
  3. 运行命令 env GIT_TERMINAL_PROMPT=1 go get github.com/company/privaterepo
英文:

the solution which worked for me;

  1. go env -w GOPRIVATE=github.com/company
  2. git config --global url."https://username:accesstoken@github.com".insteadOf "https://github.com"
  3. env GIT_TERMINAL_PROMPT=1 go get github.com/company/privaterepo

huangapple
  • 本文由 发表于 2021年12月14日 05:19:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/70341047.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定