How to fix "invalid version" and "could not read Username" in "go get" of a private repository?

Viewed 23644

I want to use private repositories that are hosted at GitHub in another GoLang-project.

What I did:

  1. I created a private access token at my GitHub account settings
  2. did then:

    git config --global url."https://xxxxxx:ACCESS_TOKEN@github.com".insteadOf "https://github.com"

with "xxxxxx" as my real GitHub username and then the proper ACCESS_TOKEN.

  1. go get github.com/private/repo

However, I get always the following error:

go: downloading github.com/xxxxxxxx/yyyyyyyyy-go-sdk v0.0.0-20200307154628-cbcb73911013
go get github.com/xxxxxxxx/yyyyyyyyy-go-sdk: github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: verifying module: github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: reading https://sum.golang.org/lookup/github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: 410 Gone
    server response:
    not found: github.com/xxxxxxxx/yyyyyyyyy-go-sdk@v0.0.0-20200307154628-cbcb73911013: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/5eca4f397ed3a418f58ee864965ed24936e21268780304d6941f5b3983d31ad1: exit status 128:
        fatal: could not read Username for 'https://github.com': terminal prompts disabled

I have also tried the following:

GONOSUMDB=github.com/myusername go get github.com/xxxxxx/yyy...

And according to some answers at StackOverflow for similar issues I tried to add ".git" after the repo-url. But this won't work at all.

What could this be and how can I fix this?

Versions:

♠ git --version
git version 2.25.0
hub version 2.14.2

♠ go version 1.14

2 Answers

You did almost everything right, and only forgot one important step.

You need to tell Go to not check checksums, as you are operating on your own private repositories:

go env -w GOPRIVATE=github.com/mycompany/*

Replace mycompany with your username on github or the name of your company and go get will most likely work as expected.

I have a solution that might help. this problem occurs in Golang version above 1.13. This happens when we use a private module in our project. Due to the Go Get command run, the golang will do a proxy checksum. So the alternative is you need to add GOPRIVATE environment in your environment.

export GOPRIVATE="github.com/private/repo"

Or if it doesn't work, try adding with GONOPROXY environment.

export GONOPROXY="github.com/private/repo"
Related