99

I started working on a Go project and it uses some private modules from Github private repos and whenever I try to run go run main.go it gives me a below 410 Gone error:

verifying github.com/repoURL/go-proto@v2.86.0+incompatible/go.mod: github.com/repoURL/go-proto@v2.86.0+incompatible/go.mod: reading https://sum.golang.org/lookup/github.com/!repoURL/go-proto@v2.86.0+incompatible: 410 Gone

I can easily clone private repo from terminal which means my ssh keys are configured correctly. I read here that I need to set GOPRIVATE environment variable but I am not sure how to do that.

Can anyone answer or point to the relevant tutorial?

Go: v1.13, OS: macOS Mojave

7
  • 2
    There's a go help for that: go help module-private
    – Soroush
    Mar 2, 2020 at 16:32
  • 2
    Or just to make live easier, export GOPRIVATE=*
    – Jay
    Aug 24, 2020 at 3:45
  • 1
    That's an excellent question. Mar 14, 2021 at 15:05
  • 4
    I was gonna ask how to add multiple path when exporting GOPRIVATE. I've tried export GOPRIVATE="github.com/repo01;gitlab.com/repo02" but didn't work. But, after looking @Jay 's comment, I tried export GOPRIVATE=* and it just works 😂 Btw, I think the go help for that right now is moving to go help private
    – Piko Monde
    Nov 19, 2021 at 10:18
  • 2
    @PikoMonde Yep, that works, or use a comma as the separator.
    – Jay
    Nov 19, 2021 at 12:08

3 Answers 3

162

Short Answer:

go env -w GOPRIVATE=github.com/repoURL/private-repo

OR

If you want to allow all private repos from your organization

go env -w GOPRIVATE=github.com/<OrgNameHere>/*

Long Answer:

Check "Module configuration for non-public modules" for more information:

The GOPRIVATE environment variable controls which modules the go command considers to be private (not available publicly) and should therefore not use the proxy or checksum database. The variable is a comma-separated list of glob patterns (in the syntax of Go's path.Match) of module path prefixes. For example,

 GOPRIVATE=*.corp.example.com,rsc.io/private

causes the go command to treat as private any module with a path prefix matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private, and rsc.io/private/quux.

. .

The 'go env -w' command (see 'go help env') can be used to set these variables for future go command invocations.


Note on the usage of ssh:

If you use ssh to access git repo (locally hosted), you might want to add the following to your ~/.gitconfig:

[url "ssh://git@git.local.intranet/"]
       insteadOf = https://git.local.intranet/

for the go commands to be able to access the git server.

7
  • 3
    Thanks! Working now so the trick was to use wildcard url with organization name. go env -w GOPRIVATE=github.com/{OrgNameHere}/*
    – UsamaAmjad
    Oct 9, 2019 at 15:21
  • Probably easier for people who code primarily with private code export GOPRIVATE=*
    – Jay
    Aug 24, 2020 at 3:46
  • 3
    Using export GOPRIVATE=* assigns all file names in the current directory to GOPRIVATE, which isn't what you want. Sep 7, 2020 at 22:31
  • That is an excellent answer. Thank you for that answer. I liked that answer. Mar 14, 2021 at 15:08
  • 4
    When executing in zsh the commands give zsh: no matches found. Escape the asterix by writing \* so it doesn't expand on it.
    – Marko
    Feb 2, 2022 at 12:27
15

Just a follow up on the usage of ssh, this is the command used to get it working:

GitHub:

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

Bitbucket:

git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"
15

If zsh use:

go env -w GOPRIVATE='gitlab.my_firm_name.com/*'

otherwise get

zsh: no matches found: GOPRIVATE=gitlab.my_firm_name.com/*

2
  • this resolved the error for zsh thanks May 18, 2022 at 18:05
  • Works for fish shell as well Jan 16 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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