3

Our private organization GitHub account is authenticated via

  1. Two-factor authentication

  2. Personal access token

When I am trying to get go module via go get which is in the private organization Github

unrecognized import path "<repo>/api?go-get=1: no go-import meta tags ()

I found a similar thread but the solution didn't work for me

What's the proper way to "go get" a private repository?

Also, I found https://medium.com/@dayakar88/a-guide-to-solve-no-go-import-meta-tags-for-private-repositories-with-go-modules-6b9237f9c9f seems proper solution for my case but I can't understand the solution

1 Answer 1

3

I've accomplished this by setting up the go for non-public modules passing the Github account as the value.

And by configuring the proxy to fetch it directly.

Optionally, you can force the go get command to use the Github personal access token in the URL ou the SSH (if you let the http:// will fail, since it'll not have access to the repository)

EXPORT GOPRIVATE=github.com/YOURACCOUNT && \
EXPORT GOPROXY=direct && \
git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf https://github.com/
5
  • https://${GITHUB_TOKEN}@github.com/ are you sure we only token here? i Aug 25, 2020 at 16:30
  • Only the token is required, you can optionally add your github username
    – twsouza
    Aug 25, 2020 at 17:56
  • I have tried the following way export GOPRIVATE=github.developer.allianz.io/<my-account-name> export GOPROXY=direct go get -u <pkgname> But still the same error Aug 26, 2020 at 3:43
  • You have to define the Github token in the URL, otherwise, it will not work.
    – twsouza
    Aug 27, 2020 at 12:53
  • Hopefully google picks this up... This is what I needed to add to my Github Action to ensure go get would work during go build and go test. I added the env vars as noted, and then did run: git config --global --add url."https://${{ secrets.MY_TOKEN }}@github.com/".insteadOf https://github.com/ where MY_TOKEN is a personal access token that has repo permissions and has access to my org's private repos. This solves fatal: could not read username
    – Finster
    Apr 27, 2022 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.