Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go Mod Private Repo

Tags:

go

vgo

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.

like image 870
user1179567 Avatar asked Sep 06 '18 17:09

user1179567


People also ask

What is Goprivate used for?

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.

What is Gonosumdb?

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.

Does Go mod use Git?

Go modules are distributed from version control repositories, commonly Git repositories.

How is Go sum generated?

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.


2 Answers

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.

like image 141
Ricardo La Rosa Avatar answered Oct 10 '22 16:10

Ricardo La Rosa


(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.

like image 31
timjonesdev Avatar answered Oct 10 '22 15:10

timjonesdev