So I have a private repo that my main.go
imports. I'm getting this error when I do a go build:
cannot find module for path
Do I need to do anything special for a private repo? I have been googling and can't find any good information. It works fine with dep.
GOPRIVATE: lists packages that are considered private. The go command does not use the GOPRIVATE or checksum database when downloading and validating these packages. Read more about GOPRIVATE in Module configuration for non-public modules at golang.org.
GONOSUMDB. The inverse of GOSUMDB , According to the official docs, is a list of glob patterns (acting as module path prefixes) which go should not verify checksums against using the checksum database. When not set the default value comes from GOPRIVATE if present.
Go modules are distributed from version control repositories, commonly Git repositories.
The go. sum is an auto-generated dependencies lock file. Modules allow us to define precise dependency requirements and design reproducible builds for multiple environments. Third-party modules are downloaded from their repositories into a module cache.
Do this
git config --global --add url."[email protected]:".insteadOf "https://your-repo.com/"
export GOPRIVATE='your-repo.com'
Make sure your git clone via ssh works.
(Answer duplicated from this SO Question)
I wrote up a solution for this on Medium: Go Modules with Private Git Repositories.
The way we handle it is basically the same as the answer from Alex Pliutau, and the blog goes into some more detail with examples for how to set up your git config with tokens from GitHub/GitLab/BitBucket. It also goes into a working Dockerfile example for using modules with private repos.
The relevant bit for GitLab:
git config --global \
url."https://oauth2:${personal_access_token}@privategitlab.com".insteadOf \
"https://privategitlab.com"
#or
git config --global \
url."https://${user}:${personal_access_token}@privategitlab.com".insteadOf \
"https://privategitlab.com"
I hope it's helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With