Go get拉错了存储库



我的模块是gitlab.com/getsote/utilities/slogger我的存储库是gitlab.com/getsote/utilities/slogger.git当我运行go get gitlab.com/getsote/utilities/slogger时,我会收到下面的消息。

Scotts-Mac-mini:seeding syacko$ go get gitlab.com/getsote/utilities/slogger
go get gitlab.com/getsote/utilities/slogger: module gitlab.com/getsote/utilities/slogger: git ls-remote -q origin in /Users/syacko/workspace/sotesoft/golang/pkg/mod/cache/vcs/80b3644beae1b986f1c659355360479e2463820660aa328d2edb1e571aba259b: exit status 128:
remote: The project you were looking for could not be found.
fatal: repository 'https://gitlab.com/getsote/utilities.git/' not found
Scotts-Mac-mini:seeding syacko$ 

gitlab.com/getsote/utilities.git是一个子目录,而不是存储库。我不明白为什么go get要作为存储库进入实用程序?

==========================

以前的更新

目录结构:

GOPATH/src/slogger
|----go.mod
|----slogger.go
|----slogger_test.go
go.mod file
module slogger  or  gitlab.com/getsote/utilities/slogger -> still gets the error below
go 1.14
gitlab.com/getsote/utilities contains repository slogger.git

我已经运行了一个测试,看看问题是否在于路径中的节点数量。因此,我创建了一个没有子目录的新存储库,并推送了slogger代码。然后运行go get gitlab.com/getsote/slogger,生成不同的错误消息。

GOPATH/gitlab.com/getsote/test-go-mod -> create new directory and added slogger files listed above
gitblab.com/getsote/test-go-mod -> new repository with one less level
Scotts-Mac-mini:test-go-mod syacko$ go get gitlab.com/getsote/test-go-mod
go: downloading gitlab.com/getsote/test-go-mod v0.0.0-20200409023538-794310bf7cf9
go get gitlab.com/getsote/test-go-mod: gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: verifying module: gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: reading https://sum.golang.org/lookup/gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: 410 Gone
server response:
not found: gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/7753c92c9bd1419156d8120684b7f3707fd207e01a2947ba89e2acfd2ecfb4d0: exit status 128:
fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
Scotts-Mac-mini:test-go-mod syacko$ 

对于丢失的版本,这仍然得到128的状态错误。此外,它正在寻找代码的正确位置。如果这是真的,那么我只需要帮助丢失版本。移动到一个简短的目录结构是可行的。

==============================

最新更新

@praveent>上的解决方案https://medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4对我不起作用。所以我从头开始,看看如何解决这个问题。

原因是,对于git存储库,它假设实用程序是repo,而不是实用程序/slogger

有一种方法可以通过实现go-get API来覆盖此行为。但是,出于安全考虑,gitlab还没有实现同样的功能。你可以在这里阅读更多。Gitlab发布

更新:添加对跟踪此问题的gitlab问题的引用。

所以,以下是我如何使用gitlab.com实现这一点的。我并不是说其他方法不起作用,它们只是不适合我和我的设置。首先,由于我不在乎代码是否对公众开放,我在gitlab.com上创建了一个新组。这个新组从一开始就是公共的,所以不需要调整权限。然后,我创建了一个名为packages的存储库,并将该存储库克隆到我的本地机器上,其目录结构与gitlab.com中的目录结构相同,gitlab.com/soteapps/packages~/workspace/soteapps/packages在我的机器上。这两人都站在了共和党一边。我不确定这是否重要,但它是这样工作的,所以我把它放在这里。

在包下,我复制了slogger目录和代码。

cp -R slogger ~/workspace/soteapps/packages/.

已编辑go.mod文件以匹配packages目录中的存储库结构。slogger目录中没有go.mod文件。

module gitlab.com/soteapps/packages
go 1.14

已编辑hello.go导入以匹配程序包。

package main
import (
"fmt"
"rsc.io/quote"
"gitlab.com/soteapps/packages/slogger"
)
func main() {
fmt.Println(quote.Hello())
slogger.Info("Test message")
}

使用go build -o hello构建程序,然后运行hello,结果如下:

Scotts-Mac-mini:hello syacko$ hello
Hello, world.
INFO:2020/04/10 21:11:33 Test message
Scotts-Mac-mini:hello syacko$ 

成功了!谢谢你的帮助。如果没有你的帮助,这个问题是不会解决的。

注意:这只适用于公共存储库

相关内容

最新更新