我正在寻找获得$ go与私人存储库工作的方法,经过许多谷歌尝试。

第一次尝试:

$ go get -v gitlab.com/secmask/awserver-go
Fetching https://gitlab.com/secmask/awserver-go?go-get=1
https fetch failed.
Fetching http://gitlab.com/secmask/awserver-go?go-get=1
Parsing meta tags from http://gitlab.com/secmask/awserver-go?go-get=1 (status code 200)
import "gitlab.com/secmask/awserver-go": parse http://gitlab.com/secmask/awserver-go?go-get=1: no go-import meta tags
package gitlab.com/secmask/awserver-go: unrecognized import path "gitlab.com/secmask/awserver-go

是的,它没有看到元标签,因为我不知道如何提供登录信息。

第二次尝试:

按照https://gist.github.com/shurcooL/6927554。将config添加到.gitconfig。

[url "ssh://git@gitlab.com/"]
    insteadOf = https://gitlab.com/
$ go get -v gitlab.com/secmask/awserver-go --> not work
$ go get -v gitlab.com/secmask/awserver-go.git --> work but I got src/gitlab.com/secmask/awserer-go.git

是的,它的工作,但与。git扩展与我的项目名称,我可以重命名为原来的,但每次做$ go get不太好,有没有其他方法?


当前回答

在设置GOPRIVATE和git配置后…

人们在获取私有资源时仍然会遇到这样的问题:

https fetch: Get "https://private/user/repo?go-get=1": EOF

他们不能使用私人回购没有。git扩展名。

原因是go工具不知道这个repo的VCS协议,git或svn或其他任何协议,不像github.com或golang.org,它们是硬编码到go的源代码中。

然后go工具将在获取你的私有repo之前执行一个https查询:

https://private/user/repo?go-get=1

如果你的私人回购不支持https请求,请使用replace直接告诉它:

require private/user/repo v1.0.0

...

replace private/user/repo => private.server/user/repo.git v1.0.0

https://golang.org/cmd/go/#hdr-Remote_import_paths

其他回答

以上所有的方法对我都不起作用。克隆回购工作正确,但我仍然得到一个无法识别的导入错误。

因为它代表Go v1.13,我在文档中发现我们应该像这样使用GOPRIVATE env变量:

$ GOPRIVATE=github.com/ORGANISATION_OR_USER_NAME go get -u github.com/ORGANISATION_OR_USER_NAME/REPO_NAME

如果你已经使用SSH得到git, Ammar Bandukwala的回答是一个简单的解决方案:


$ go get内部使用git。下面的一行代码将使git和$ go get通过SSH克隆你的包。

Github:

$ git config --global url."git@github.com:".insteadOf "https://github.com/"

BitBucket都:

$ git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"

在尝试了多种解决方案后,我的问题仍然存在。设置~/.netrc和SSH配置文件后的最终解决方案是在~/.bash_profile中添加以下行

出口GOPRIVATE = " github.com/(组织)”

在这里生成一个github oauth令牌,并将您的github令牌作为环境变量导出:

export GITHUB_TOKEN=123

设置git配置为使用基本认证url:

git config --global url."https://$GITHUB_TOKEN:x-oauth-basic@github.com/".insteadOf "https://github.com/"

现在你可以去拿你的私人回购了。

我第一次尝试

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/

但在我的本地车里,它不管用。

我试着

SSH -t git@github.com

它显示我的SSH是好的。

最后,我解决了这个问题,告诉go get考虑所有的私有和使用ssh而不是HTTPS。

添加export GOPRIVATE=*