简体   繁体   中英

Cannot install private Go module

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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