【发布时间】:2019-10-11 17:45:23
【问题描述】:
我正在将一些私有 Go 项目转移到 GitLab,同时摆脱 Godeps、带有 vendor 目录的 Go dep 以及所有这些,因为我只想使用 Go 模块。
我使用的是 Go 版本:go1.12.6 linux/amd64。
- 我在
gitlab.com/my-company/my-team/my-library有一个私有“库”项目/git 存储库。这与go.mod和go.sum一起作为 Go 模块工作。 - 我想使用
my-library作为另一个项目的依赖项,这个:gitlab.com/my-company/my-team/my-project。
URL 的结构是一样的,唯一改变的是存储库的名称。
在my-project 中导入my-library 时遇到各种错误。
- 如何将 Go 模块作为私有仓库导入到其他 Go 模块中作为私有仓库?
- 下面的命令输出有什么问题?
我知道 GitLab 令牌可以工作,因为 go get 命令会自行计算出 my-library 的提交 ID。无论如何,我做了以下事情(见https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html):
git config \
--global \
url."https://token_name:token_val@gitlab.com".insteadOf \
"https://gitlab.com"
这些是错误消息:
$ go get -u gitlab.com/my-company/my-team/my-library.git
go: finding gitlab.com/my-company/my-team/my-library.git latest
go: gitlab.com/my-company/my-team/my-library.git@v0.0.0-20190802120216-712a10fb5fac: parsing go.mod: unexpected module path "gitlab.com/my-company/my-team/my-library"
go get: error loading module requirements
$
$ go get -u gitlab.com/my-company/my-team/my-library
go get gitlab.com/my-company/my-team/my-library: git ls-remote -q https://gitlab.com/my-company/my-team.git in /home/foo/Development/go-workspace/pkg/mod/cache/vcs/9be637426eac43b329899d57d9375d12246f2cc0f6ddd098446bc42ed1ca534d: exit status 128:
remote: The project you were looking for could not be found.
fatal: repository 'https://token_name:token_val@gitlab.com/my-company/my-team.git/' not found
$
$ GO111MODULE=off go get -u gitlab.com/my-company/my-team/my-library.git
package gitlab.com/my-company/my-team/my-library.git: no Go files in /home/foo/Development/go-workspace/src/gitlab.com/my-company/my-team/my-library.git
$
- 第一次尝试是我认为我应该使用的,但它不起作用,我不知道为什么。
- 我认为这是因为项目中已经存在这样的依赖项。但是在执行
go mod graph | grep gitlab时,我发现一个空输出,即没有冲突的依赖关系。
- 我认为这是因为项目中已经存在这样的依赖项。但是在执行
- 可能要避免第二次尝试,因为 URL 不以
.git结尾,并且(出于某种我不明白的原因)URL 被剪切到my-team的级别。 -
GO111MODULE=off似乎迫使go get签入$GOPATH,我认为我应该避免这样做,但我只是想看看我是否能够以这种方式获取该依赖项。
【问题讨论】:
标签: git go gitlab go-modules