Go modules, private repos and gopath

go mod private repo
go mod private repo 410 gone
go mod unknown revision private repo
go.mod replace
cannot find module providing package private repo
go get private repo docker
go mod incompatible
go get github repo

We are converting our internal codebase from the dep dependency manager to go modules (vgo or built in with go1.11.2). Imagine we have code like this:


package main

import (
        lib "mycompany/mylib" )

func main() {
        fmt.Println("2+3=", lib.add(2, 3)) 


module mycompany/myprogram

(it doesn't have any dependencies; our real-world code does).


package mylib

func Add(x int, y int) int {
        return x + y

I didn't module-ize this code; it doesn't seem to matter whether I do or don't.

These are trivial examples but our internal code follows a similar structure as this worked historically.

Since these directories are on the Gopath, export GO111MODULE=auto still builds as before and this works fine (modules not used because we are on the gopath). However, when I set export GO111MODULE=on I immediately get the error:

build mycompany/myprogram: cannot find module for path mycompany/mylib

So I did some research and I would like to validate my understanding. First let me say our old approach worked, but I am more interested in changing to use go modules as it appears to be where the go project itself is headed. So.

  1. It seems the intention of the golang authors was that "dotless" paths belong to the standard repository only; that is there should be a binding between domain name and project. We don't use go get on our internal project, unsurprisingly. Here is the source specifically:

    Dotless paths in general are reserved for the standard library; go get has (to my knowledge) never worked with them, but go get is also the main entry point for working with versioned modules.

    Can anyone with more knowledge of golang than me confirm this?

  2. My key assumption is that once go decides to use modules, all dependencies must be modules and the gopath becomes somewhat irrelevant, except as a cache (for downloaded modules). Is this correct?

  3. If this is true, we need to use a private gitlab (in our case) repository on the path. There's an open issue on handling this that I'm aware of so we can implement this if necessary. I'm more interested in the consequences, specifically for iterating in the private repositories. Previously we could develop these libraries locally before committing any changes; now it seems we have a choice:

    1. Accept this remote dependency and iterate. I was hoping to avoid needing to push and pull remotely like this. There are workarounds to needing an internet connection if strictly necessary.
    2. Merge everything into one big git repository.

If it matters, I'm using go version go1.11.2 linux/amd64 and my colleagues are using darwin/amd64. If it helps, my golang is exactly as installed by Fedora's repositories.

So, tl;dr, my question is: are go modules all-or-nothing, in that any dependency must be resolved using the module system (go get, it seems) and the gopath has become redundant? Or is there something about my setup that might trigger this to fail? Is there some way to indicate a dependency should be resolved explicitly from the gopath?

Updates since asking the question:

  1. I can move myprogram out of the gopath. The same issue occurs (mylib has been left in the gopath).
  2. I can run, or not run, go mod init mycompany/mylib in the mylib directory; it makes no difference at all.
  3. I came across Russ Cox's blog post on vgo. My concerns about offline development that I tried not to dive into too far are resolved by $GOPROXY.

I use a workaround with GITHUB_TOKEN to solve this.

  1. Generate GITHUB_TOKEN here https://github.com/settings/tokens
  2. export GITHUB_TOKEN=xxx
  3. git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/mycompany".insteadOf "https://github.com/mycompany"

Go Modules with Private Git Repositories, your development environment to allow Go Modules to work with private Git repositories. What is the best IDE for developing in Golang? Private Repositories. Under the hood, Go is using Git to pull the specified versions of your dependencies. So, the git configuration for wherever Go is running (eg. a Docker container or your

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

The relevant bit for GitLab:

git config --global \
  url."https://oauth2:${personal_access_token}@privategitlab.com".insteadOf \


git config --global \
  url."https://${user}:${personal_access_token}@privategitlab.com".insteadOf \

I hope it's helpful.

Fetching Private Dependencies with Go Modules, Modules are the future of package distribution in Go. Token” in Github with scopes that allow it to read private repositories. golang:1.12-alpine3.8# Moving outside of $GOPATH forces modules on without having to set Converting the entire ecosystem — code, users, tools, and so on — from GOPATH to modules will require work in many different areas. Since 1.12 version Go modules is enabled by default and the GOPATH will be deprecated in 1.13 version. For those who are getting started with Go 1.12, the installation and set up goes will be as follows.

I use ls-remote git command to help resolve private repo tags and go get after it.

$ go env GO111MODULE=on
$ go env GOPRIVATE=yourprivaterepo.com
$ git ls-remote -q https://yourprivaterepo.com/yourproject.git
$ go get

cmd/go: custom import path private repos require special , import "private.repo.net/user/package/a". This used to work when using the old $​GOPATH . Now I am trying to use modules instead. I run go  This might seem a bit off-topic but I posted it here since I'm a big fan of GO and now primarily work with systems built with GO and so I will be inviting a lot of people building GO infra to talk with us. Please reach out if you'd like to join one of our chats and tell us about your work with GO infra.

cmd/go: permit marking a module as private in go.mod · Issue , The major problem with indicating private repos in the go.mod file is it is proxy.​golang.org or something else — then those modules become  use go get on a private bitbucket repo with modules enabled. What did you expect to see? I expected the private repository to be pulled to the appropriate ${GOPATH}/pkg/mod directory. What did you see instead?

Migrating to Go Modules - The Go Blog, Some projects store their entire GOPATH directory in a single Git repository. Others simply rely on go get and expect fairly recent versions of  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more How to fix “go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src”

Go module with private gitlab repos : golang, Go module with private gitlab repos. I am trying to configure a dependency arch based on the new 1.11 feature : modules. The problem I get is that my projects  The new custom import path checking behavior introduced in Go 1.4 makes it extremely difficult to work with private Github repositories. Before Go 1.4, the traditional way to work with a private Github repository was to run something sim