如何处理Go的虚构URL和主要版本子包?

huangapple go评论80阅读模式
英文:

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

问题

我正在使用Go的虚拟URL设置,但我在解析超过v0和v1的模块时遇到了困难。

解析模块的v1版本似乎一切正常。但是,当我尝试在子文件夹中创建一个新的主要版本时,似乎无法解析该模块。我尝试过添加和不添加v2的go-import条目,但它们都给出了一些奇怪的结果。

当我没有v2的条目时,我会收到以下错误:

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

当我添加了一个条目时,我会收到以下错误:

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

无论哪种方式,它都不像我期望的那样工作。我在这个存储库中复现了我的问题https://github.com/tomasruud/gvm,因此通过尝试运行go get tomasruud.github.io/gvm/v2@v2.0.0应该能够看到相同的行为。

英文:

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/v2@v2.0.0
go: tomasruud.github.io/gvm@v2.0.0: 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/v2@v2.0.0
go: tomasruud.github.io/gvm/v2@v2.0.0: 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/v2@v2.0.0.

答案1

得分: 0

所以为了回答我自己的问题,看起来我为我的子模块设置的元标签配置不正确。最初,我将v2子模块的元标签配置为<meta name="go-import" content="tomasruud.github.io/gvm/v2 git https://github.com/tomasruud/gvm">,这使得go get假设我的git项目的根目录暴露了包tomasruud.github.io/gvm/v2

tomasruud.github.io/gvm/v2的元标签更改为<meta name="go-import" content="tomasruud.github.io/gvm git https://github.com/tomasruud/gvm">后,它现在按预期工作。请注意,此处内容字段的第一部分指向存储库根目录中找到的模块的名称。因此,这似乎是此问题的根本原因。

有关更多详细信息,请查看Github上的此问题

英文:

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.

huangapple
  • 本文由 发表于 2023年2月22日 23:10:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75534660.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定