Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: auto-find module from package import #43493

fwhezfwhez opened this issue Jan 4, 2021 · 2 comments

cmd/go: auto-find module from package import #43493

fwhezfwhez opened this issue Jan 4, 2021 · 2 comments


Copy link

@fwhezfwhez fwhezfwhez commented Jan 4, 2021

In my company, There're many packages local and saved in restricted git repo.

To import those pkgs, I'm doing like :

package main

import (

Desperately xxx module not found. Even if I've already put xxx into $GOPATH/pkg/mod/xxx.

To fix this ,I must type

requires xxx
replace xxx ../../pkg/mod/xxx

It seems estremely bad and extra. Because once I put my projects not in GOPATH/src, the replace will changed to ../../../../path-togopath/pkg/mod/xxx. Also it doesnt support 'replace xxx $GOPATH/pkg/mod/xxx'.

Suggest full path or from root?

No, because a repo will be developed by all kinds of os, besides, remote machie and local machine might have different root format.

Thus, I hope gomodule can support auto-find pkg. It seems easy realized just like GOPATH.

  • first, make sure xxx pkg is at GOPATH/pkg/mod/xxx
  • import xxx

Just throw 'replace' and 'require' away on this case!

@toothrot toothrot changed the title [feature-requiring]Go module supports auto-find pakcage via GOPATH/pkg/mod/xxx!! cmd/go: auto-find module from package import Jan 5, 2021
@toothrot toothrot added this to the Backlog milestone Jan 5, 2021
Copy link

@toothrot toothrot commented Jan 5, 2021

It seems like this would be non-deterministic if two packages have the same name.

/cc @bcmills @jayconrod @matloob

Copy link

@jayconrod jayconrod commented Jan 5, 2021

This is probably not feasible. The module cache ($GOPATH/pkg/mod) should not be modified manually, and the go command shouldn't look anywhere else for imported packages.

Is there a reason you can't use one of the workflows for private repositories described in Private modules? In most cases, you'd name your module after the repository URL (like or, then set or

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.