简体   繁体   English

无法安装私有 Go 模块

[英]Cannot install private Go module

I have a private project which uses a private module at github.com/company/company-product .我有一个私有项目,它在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/配置 git 使用ssh://git@github.com/而不是https://github.com/
  • Configured git to use ssh://$PERSONAL_ACCESS_TOKEN@github.com/ instead of https://github.com/配置 git 使用ssh://$PERSONAL_ACCESS_TOKEN@github.com/而不是https://github.com/
  • Deleted everything in $GOPATH/pkg删除$GOPATH/pkg中的所有内容
  • go clean
  • go mod download , go mod tidy , go mod vendor (which all produce the above error) go mod downloadgo mod tidygo mod vendor (都产生上述错误)
  • Restarted my computer重新启动我的电脑
  • Connected to my company's VPN连接到我公司的VPN

And yet I still get the same error.但是我仍然遇到同样的错误。

It looks like the key was to do things in a certain order:看起来关键是按照一定的顺序做事:

  1. Reinstall Go重新安装 Go
  2. Set environment variables GOPRIVATE, GONOPROSXY, GONOSUMDB to github.com/company/*将环境变量GOPRIVATE、GONOPROSXY、GONOSUMDB设置为github.com/company/*
  3. Remove the folder $GOPATH/pkg删除文件夹$GOPATH/pkg
  4. Setup Git to use ssh://git@github.com/ instead of https://github.com/设置 Git 使用ssh://git@github.com/而不是https://github.com/
  5. Run go get github.com/company/company-product运行go get github.com/company/company-product

the solution which worked for me;对我有用的解决方案;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM