我正在寻找获得$ 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不太好,有没有其他方法?
如果你已经使用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/"
在设置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
如果你已经使用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/"