gomodpriv is a tool to automatically manage the GOPRIVATE
environment
variable used by go1.13+.
Installation is simple and no different to any Go tool. The only requirement is a working Go install.
go get go.tmthrgd.dev/gomodpriv
The GOPRIVATE environment variable is set to a list of all private repositories
owned by the current GitHub user. It reads go.mod
files in the root
directory, to handle any custom import paths.
When run for the first time you will be prompted for your GitHub username and password. Your password is not stored, but instead used to request an Oauth2 token.
By default the list of private repositories are cached for faster terminal
start-ups. The cache can be refreshed by running gomodpriv directly, or
adding -cache=false
to the .bashrc
line below.
Add the following to your .bashrc
file to set the GOPRIVATE environment
variable when a terminal is opened:
export GOPRIVATE=$(gomodpriv -env)
If you want the list of private repositories to be refreshed periodically, ensure gomodpriv is run at start-up or upon login. Otherwise it can be run manually when creating new private repositories.
gomodpriv (mis)uses github/hub to handle authentication. If hub is already installed, you may not be prompted for your username and password. To have this work with GitHub enterprise follow the instructions found here: hub.github.com/hub.1.html#github-enterprise.