我正在使用golang 1.13。
我有一个依赖于私人gitlab项目的项目。
我有相同的ssh键。
当我尝试为新创建的模块检索依赖项时,出现以下错误:
$ go version
go version go1.13 linux/amd64
$ go mod why
go: downloading gitlab.com/mycompany/myproject v0.0.145
verifying gitlab.com/mycompany/myproject@v0.0.145: gitlab.com/mycompany/myproject@v0.0.145: reading https://sum.golang.org/lookup/gitlab.com/mycompany/myproject@v0.0.145: 410 Gone
Run Code Online (Sandbox Code Playgroud)
我不知道为什么要尝试ping sum.golang.org/lookup,因为它是一个私有gitlab项目。
我的〜/ .gitconfig包含以下内容(基于我在google搜索中查找的类似错误)
# Enforce SSH
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
insteadOf = https://gitlab.com/
[url "ssh://git@bitbucket.org/"]
insteadOf = https://bitbucket.org/
[url "git@gitlab.com:"]
insteadOf = https://gitlab.com/
Run Code Online (Sandbox Code Playgroud)
该错误仍然存在。
我希望将软件包从我的私人gitlab项目存储库下载到当前项目。
我有什么需要在我的私有gitlab项目存储库中做的事情,以使其准备好“开始使用”?
私有gitlab项目存储库已经包含该项目的go.sum和go.mod。
我有什么想念的吗?
编辑:1)私人回购名称和公司名称不包含星号或任何其他特殊字符。只有字母,甚至没有数字字符。
nov*_*ack 20
抬头回答我自己的问题,
设置GOPRIVATE变量似乎有所帮助。
GOPRIVATE=gitlab.com/mycompany/* go mod why
Run Code Online (Sandbox Code Playgroud)
“新的GOPRIVATE环境变量指示了不可公开使用的模块路径。它用作较低级别的GONOPROXY和GONOSUMDB变量的默认值,它们提供了更细粒度的控制,可通过代理获取哪些模块并使用校验和数据库进行验证来自https://golang.org/doc/go1.13。
升:
设置环境变量GONOSUMDB似乎也可以。具体来说,调用以下命令似乎有所帮助。
GONOSUMDB=gitlab.com/mycompany/* go mod why
Run Code Online (Sandbox Code Playgroud)
上面的env变量阻止ping到sum.golang.org/lookup以进行校验和匹配。它还可以防止将私有存储库的名称泄露给公共校验和数据库。[来源-https: //docs.gomods.io/configuration/sumdb/ ]
另外-在这里
* GONOSUMDB=prefix1,prefix2,prefix3 sets a list of module path prefixes, again possibly containing globs, that should not be looked up using the database.
Run Code Online (Sandbox Code Playgroud)
来源:https://go.googlesource.com/proposal/+/master/design/25530-sumdb.md
相关问题:
基本上它无法验证私有存储库。但是我不喜欢关闭校验和,但是您可以在尝试获取模块之前轻松设置GOSUMDB为off。像这样:
GOSUMDB=off go get github.com/mycompany/myproject
Run Code Online (Sandbox Code Playgroud)
参考:https : //github.com/golang/go/issues/35164#issuecomment-546503518
第二个更好的解决方案是设置GOPRIVATE环境变量来控制 go 命令认为哪些模块是私有的(不公开),因此不应使用代理或校验和数据库。该变量是path.Match模块路径前缀的 glob 模式(与 Go 的语法相同)的逗号分隔列表。例如,
export GOPRIVATE=*.corp.example.com,rsc.io/private
Run Code Online (Sandbox Code Playgroud)
或者
go env -w GOPRIVATE=github.com/mycompany/*
Run Code Online (Sandbox Code Playgroud)
您可以尝试的最后一个解决方案是关闭对您不想公开或通过验证的所有私有存储库的此类检查 sum.golang.org/lookup/github.com/mycompany/...
GONOSUMDB=gitlab.com/mycompany/* go mod why
Run Code Online (Sandbox Code Playgroud)
注意:
如果您有获取模块或回购通过HTTPS的问题,您可能需要以下添加到您~/.gitconfig做出go获取/读取使用存储库ssh,而不是https
[url "ssh://git@github.com/"] 代替 = https://github.com/