go get无法从GitHub上的私有仓库获取模块。

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

go get can't get a module from a private repo on github

问题

go get 命令无法检索您的模块的问题可能是由于以下原因之一引起的:

  1. 模块路径不匹配:根据错误消息,您的模块在 go.mod 文件中声明的路径是 "key-value-mod",但是在 go get 命令中使用的路径是 "github.com/dwschulze/key-value-mod"。请确保在 go get 命令中使用与 go.mod 文件中声明的路径完全匹配的模块路径。

  2. 版本标签不存在:根据错误消息,go get 命令在尝试获取版本为 "v0.1" 的模块时找不到匹配的版本。请确保您已经正确地为您的模块添加了 "v0.1" 的标签,并且该标签已经推送到了您的 GitHub 仓库。

  3. GOPRIVATE 设置不正确:您已经设置了 go env -w GOPRIVATE=github.com/dwschulze/key-value-mod,但是根据您提供的信息,您的模块位于私有的 GitHub 仓库中。请确保您正确地设置了 GOPRIVATE 环境变量,以便让 Go 工具知道您的模块位于私有仓库中。

请检查并确保以上几点都正确设置后,再次尝试运行 go get 命令。如果问题仍然存在,请提供更多详细信息以便我能够帮助您进一步解决问题。

英文:

I have a (private) github repo with a Go module. I've added the tag v0.1 and github shows that tag. I have set go env -w GOPRIVATE=github.com/dwschulze/key-value-mod and my ~/.gitconfig has


insteadOf = https://github.com/

But go get can't retrieve my module:

$ go get github.com/dwschulze/key-value-mod
go: github.com/dwschulze/key-value-mod upgrade => v0.0.0-20210907155619-9116b97467d6
go get: github.com/dwschulze/key-value-mod@v0.0.0-20210907155619-9116b97467d6: parsing go.mod:
        module declares its path as: key-value-mod
                but was required as: github.com/dwschulze/key-value-mod

$ go get github.com/dwschulze/key-value-mod@v0.1
go get github.com/dwschulze/key-value-mod@v0.1: no matching versions for query "v0.1"

What problem is go get having?

答案1

得分: 2

根据错误信息,我认为你的私有仓库没有问题。相反,我认为你的go.mod文件将模块声明为

module key-value-mod

...

而应该是

module github.com/dwschulze/key-value-mod

...
英文:

Based on the error, I don't think you have any issues with the private repo. Rather, it seems to me that your go.mod file declares the module as

module key-value-mod

...

while it should be

module github.com/dwschulze/key-value-mod

...

答案2

得分: 2

这是两个原因导致的。首先,我需要清除我的模块缓存。其次,正如Simon在上面提到的,模块名称必须是模块将被发布的仓库URL。

我不喜欢Go模块与源代码仓库之间的紧密耦合,但这是现实。

英文:

Two things were causing this. I had to clear my module cache. The second is as Simon mentions above the module name has to be the repo URL where the module will be published.

I don't like the close coupling that go modules have with source code repositories, but that is reality.

答案3

得分: 1

你的 go modulesv0.1 版本号对于 go modules 的使用是不正确的。它包含了 major 版本和 minor 版本,但缺少了 patch 号:

go get无法从GitHub上的私有仓库获取模块。

注意:这里的 Pre-release Identifier 后缀(-beta.2)是可选的。

请参考 publishing go modules 文档:

> 在 go.mod 文件中的每个必需模块都有一个语义化版本,即构建该模块所需的最低依赖版本。
>
> 语义化版本的格式为 vMAJOR.MINOR.PATCH.

所以,请将你的标签更新为 v0.1.0,然后应该就可以正常工作了。

英文:

Your go modules semver of v0.1 is incorrect for go modules consumption. It includes a major version, minor version - but is missing the patch number:

go get无法从GitHub上的私有仓库获取模块。

Note: the Pre-release Identifier suffix here (-beta.2) is optional.

See also publishing go modules docs:

> Every required module in a go.mod has a semantic version, the minimum
> version of that dependency to use to build the module.
>
> A semantic version has the form vMAJOR.MINOR.PATCH.

So update your tag to v0.1.0 and it should work.

huangapple
  • 本文由 发表于 2021年9月8日 00:44:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/69091905.html
匿名

发表评论

匿名网友

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

确定