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

shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129

1 Answers1

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/
twsouza
  • 93
  • 6
  • `https://${GITHUB_TOKEN}@github.com/` are you sure we only token here? i – shamon shamsudeen Aug 25 '20 at 16:30
  • Only the token is required, you can optionally add your github username – twsouza Aug 25 '20 at 17:56
  • I have tried the following way ```export GOPRIVATE=github.developer.allianz.io/ export GOPROXY=direct go get -u ``` But still the same error – shamon shamsudeen Aug 26 '20 at 03:43
  • You have to define the Github token in the URL, otherwise, it will not work. – twsouza Aug 27 '20 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 '22 at 18:51