Search code examples
gogo-modules

How to deal with Go vanity urls and major version sub packages?


I'm running a setup with Go vanity urls, but I'm struggling to figure out how to resolve modules when going beyond v0 and v1.

Everything seems to be working fine for resolving v1 of the module. But when I try to create a new major version in a sub folder, I can't seem to be able to resolve the module. I have tried both with and without adding a go-import entry for v2. But they both give some strange results.

When I don't have an entry for v2, I'm getting an error like this:

$ go get tomasruud.github.io/gvm/[email protected]
go: tomasruud.github.io/[email protected]: invalid version: module contains a go.mod file, so module path must match major version ("tomasruud.github.io/gvm/v2")

And when I add an entry for it, I'm getting an error like this:

$ go get tomasruud.github.io/gvm/[email protected]
go: tomasruud.github.io/gvm/[email protected]: go.mod has non-.../v2 module path "tomasruud.github.io/gvm" at revision v2.0.0

Either way it is not working as I expect it to. I have reproduced my issue in this repository https://github.com/tomasruud/gvm, so it should be possible to see the same behaviour by trying to run go get tomasruud.github.io/gvm/[email protected].


Solution

  • So to answer my own question here, it seems like the meta tags I had set up for my sub modules were incorrectly configured. Originally I had my v2 sub modules meta tag configured like this <meta name="go-import" content="tomasruud.github.io/gvm/v2 git https://github.com/tomasruud/gvm"> which made go get assume that the root of my git project exposed the package tomasruud.github.io/gvm/v2.

    After changing the meta tag for tomasruud.github.io/gvm/v2 to be <meta name="go-import" content="tomasruud.github.io/gvm git https://github.com/tomasruud/gvm">, it is now working as expected. Note the first part of the content field here is pointing to the name of the module found at the repository root. So this seems to have been the root cause of this issue.

    For more details check out this issue over at Github.