我正在寻找获得$ 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不太好,有没有其他方法?


当前回答

对于独立/最终回购,作为快速修复,为什么不直接在go中命名模块呢?Mod作为一个包使用贵公司的域名…?

module go.yourcompany.tld/the_repo

Go.yourcompany.tld甚至不必作为有效(子)域名存在…

同样,在同一个地方。mod你可以使用替换块/行来使用之前以同样的方式克隆的私有回购(在$GOPATH/src/go.yourcompany.tld中克隆的各自文件夹中)(为什么我们必须在GitHub中依赖太多?)

Edit

不用说,私人回购通常应该是私人回购,通常是标准的git回购,对吧?有了这些,为什么不直接克隆git,然后进入克隆文件夹?

其他回答

我已经创建了一个特定于用户的ssh-config,因此我的用户可以使用正确的凭证和密钥自动登录。

首先,我需要生成一个密钥对

ssh-keygen -t rsa -b 4096 -C "my@email.here"

并保存到例如~/.ssh/id_my_domain。请注意,这也是我连接到我的Github帐户的对口令(私有和公共),所以我的存储在~/.ssh/id_github_com。

然后我创建(或修改)了一个名为~/的文件。Ssh /config有一个条目:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_github_com

在另一个服务器上,“ssh-url”是admin@domain.com:username/private-repo.git,这个服务器的条目应该是:

Host domain.com
    HostName domain.com
    User admin
    IdentityFile ~/.ssh/id_domain_com

澄清一下,您需要确保正确设置了User、Host和HostName。

现在我可以浏览到go路径,然后去get <package>,例如去get main文件main/main。Go包含包(来自上一个例子)domain.com:username/private-repo.git。

我有一个问题,从我们公司的gitlab使用私人存储库。 我花了几分钟试图找到解决办法。我找到了这个:

你需要获得一个私人令牌: https://gitlab.mycompany.com/profile/account 配置你的git添加额外的头与你的私有令牌: $ git配置——global http。"PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN" 配置你的git将请求从http转换为ssh: $ git配置——全局url."git@gitlab.mycompany.com:". insteadof "https://gitlab.mycompany.com/" 最后你可以正常使用你的go get: $ go get gitlab.com/company/private_repo

在设置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

在这里生成一个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/"

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

正确的方法是手动将存储库放在正确的位置。一旦有了存储库,您可以使用go get -u来更新包,然后使用install来安装它。一个名为

github.com/secmask/awserver-go

进入

$GOPATH/src/github.com/secmask/awserver-go

您键入的命令是:

cd $GOPATH/src/github.com/secmask
git clone git@github.com:secmask/awserver-go.git