Tuesday 1 March 2022

Go and GitHub and downstream dependencies

 I'm leaving this here to remind the future me ...

Along with: -


 which is better documented in git-config there's also a need to do something similar when using Go with dependencies in GitHub, namely the GOPRIVATE variable, which was added in Go 1.13 as per the release notes here.

This is to mitigate this exception: -

fatal: could not read Username for 'https://github.com': terminal prompts disabled

 Confirm the import path was entered correctly.

It's also well documented from the Go CLI as per the following: -

go help private

The go command defaults to downloading modules from the public Go module
mirror at proxy.golang.org. It also defaults to validating downloaded modules,
regardless of source, against the public Go checksum database at sum.golang.org.
These defaults work well for publicly available source code.
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,
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.
For fine-grained control over module download and validation, the GONOPROXY
and GONOSUMDB environment variables accept the same kind of glob list
and override GOPRIVATE for the specific decision of whether to use the proxy
and checksum database, respectively.
For example, if a company ran a module proxy serving private modules,
users would configure go using:
The GOPRIVATE variable is also used to define the "public" and "private"
patterns for the GOVCS variable; see 'go help vcs'. For that usage,
GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
instead of module paths.
The 'go env -w' command (see 'go help env') can be used to set these variables
for future go command invocations.
For more details, see <https://golang.org/ref/mod#private-modules>.

TL;DR; this is what I needed to add: -

go env -w GOPRIVATE=github.com

No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...