Skip to content

Instantly share code, notes, and snippets.

@zMrKrabz
Created June 12, 2021 21:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zMrKrabz/386b8096a445134b8889974544c0802d to your computer and use it in GitHub Desktop.
Save zMrKrabz/386b8096a445134b8889974544c0802d to your computer and use it in GitHub Desktop.
Using private packages in Go

If you were to go get a private repository with go, you would see something like this

$ go get github.com/zMrKrabz/flyent
go: downloading github.com/zMrKrabz/flyent v0.0.0-20210612205723-a495958a84ab
go get: github.com/zMrKrabz/flyent@v0.0.0-20210612205723-a495958a84ab: verifying module: github.com/zMrKrabz/flyent@v0.0.0-20210612205723-a495958a84ab: reading https://sum.golang.org/lookup/github.com/z!mr!krabz/flyent@v0.0.0-20210612205723-a495958a84ab: 410 Gone
	server response:
	not found: github.com/zMrKrabz/flyent@v0.0.0-20210612205723-a495958a84ab: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/d455a9bff29b25fc089b95289e07ca4a6886822823a65d8b41247eae8baf04a7: exit status 128:
		fatal: could not read Username for 'https://github.com': terminal prompts disabled

In order to resolve this, use Github with SSH and set the GOPROXY to direct or set GOPRIVATE=.

  1. Create a SSH key following this guide: https://jdblischak.github.io/2014-09-18-chicago/novice/git/05-sshkeys.html
  2. Add your SSH key to github following this guide: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
  3. Run git config --global url.git@github.com:.insteadof=https://github.com
  4. To make sure that this is set, run git config --global --list
  5. Set the GOPRIVATE to a regex string that matches the private packages you're getting. For the sake of simplicity, I just do $ export GOPRIVATE=github.com/<USERNAME>/* Because if one of my private packages uses a private package, it will be able to get that private package as well.
  6. Rerun your go get command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment