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

module required error when get module in multi module repo mode #42

Open
chengjingtao opened this issue Jan 20, 2021 · 2 comments
Open

Comments

@chengjingtao
Copy link

chengjingtao commented Jan 20, 2021

Hi, I have a module mode repo like this:

// repo: https://git.mycompany.com/dev/pkg.git

├── README.md
├── go.mod    // go.mycompany.com/pkg
├── util
│   ├── go.mod   // go.mycompany.com/pkg/util
│   ├── go.sum
│   ├── xx.go
├── log
│   ├── go.mod    // go.mycompany.com/pkg/log
│   ├── go.sum
│   └── xx.go

I have add config in vanity.yaml

paths:
  /pkg/util:
    repo: https://git.mycompany.com/dev/pkg

but When execute command go get -v go.company.com/pkg/util , I got error

get "go.company.com/pkg": found meta tag get.metaImport{Prefix:"go.company.com/pkg", VCS:"git", RepoRoot:"https://git.mycompany.com/dev/pkg"} at //git.mycompany.com/pkg?go-get=1
get "go.company.com/pkg/util": found meta tag get.metaImport{Prefix:"go.company.com/pkg/util", VCS:"git", RepoRoot:"https://git.mycompany.com/dev/pkg"} at //git.mycompany.com/pkg/util?go-get=1
go: go.mycompany.com/pkg/util master => v0.1.2-0.20210120054534-86b99a469841
go get: go.mycompany.com/pkg/[email protected]: parsing go.mod:
	module declares its path as: go.mycompany.com/pkg
	        but was required as: go.mycompany.com/pkg/util

Is there any idea to resolve it ?

@danielorbach
Copy link

The toolchain supports Module directories within a repository.

Recall that a module path consists of three parts: a repository root path (corresponding to the repository root directory), a module subdirectory, and a major version suffix (only for modules released at v2 or higher).
Modules are sometimes defined in repository subdirectories. Such a module is expected to be found in a subdirectory that matches the part of the module’s path after the repository root path.
For example, suppose the module example.com/monorepo/foo/bar is in the repository with root path example.com/monorepo. Its go.mod file must be in the foo/bar subdirectory.

The following vanity.yaml should work:

host: go.mycompany.com
paths:
  /pkg:
    repo: https://git.mycompany.com/dev/pkg

For troubleshooting, when running go get -v go.company.com/pkg/util expect to see the following:

...
get "go.company.com/pkg/util": found meta tag vcs.metaImport{Prefix:"go.company.com/pkg", VCS:"git", RepoRoot:"https://git.mycompany.com/dev/pkg"} at //git.mycompany.com/pkg/util?go-get=1
...

@danielorbach
Copy link

Also note that the current latest version of this repository (2171d0d) fails to handle the path / correctly.
Here's a possible fix:

diff --git a/tools/vanity-urls/handler.go b/tools/vanity-urls/handler.go
@@ -70,6 +70,10 @@ func newHandler(config []byte) (*handler, error) {
                        display: e.Display,
                        vcs:     e.VCS,
                }
+               // A path may be "/", which is trimmed to "" above.
+               if pc.path == "" {
+                       pc.path = "/"
+               }
                switch {
                case e.Display != "":
                        // Already filled in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants