$ go get在谷歌尝试之后,我正在寻找使用私有存储库的方法.
第一次尝试:
$ 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
Run Code Online (Sandbox Code Playgroud)
是的,它没有看到meta标签,因为我不知道如何提供登录信息.
第二次尝试:
关注https://gist.github.com/shurcooL/6927554.将配置添加到.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
Run Code Online (Sandbox Code Playgroud)
是的它可以工作,但.git扩展了我的项目名称,我可以将它重命名为原始,但每次$ go get都不是那么好,是否还有其他的?
Jul*_*enD 67
根据这个链接 - https://gist.github.com/shurcooL/6927554 - 你有两件事要配置.该示例基于GitHub,但这不应该更改该过程
$ git config --global url.git@github.com:.insteadOf https://github.com/
$ cat ~/.gitconfig
[url "git@github.com:"]
insteadOf = https://github.com/
$ go get github.com/private/repo
Run Code Online (Sandbox Code Playgroud)
fuz*_*fuz 50
正确的方法是手动将存储库放在正确的位置.存储库存在后,您可以使用go get -u更新包并go install进行安装.一个名为的包
github.com/secmask/awserver-go
Run Code Online (Sandbox Code Playgroud)
进入
$GOPATH/src/github.com/secmask/awserver-go
Run Code Online (Sandbox Code Playgroud)
您键入的命令是:
cd $GOPATH/src/github.com/secmask
git clone git@github.com:secmask/awserver-go.git
Run Code Online (Sandbox Code Playgroud)
小智 30
我在我们公司的gitlab上go get使用私有存储库时遇到了问题.我试图找到一个解决方案,我失去了几分钟.我确实找到了这个:
您需要获取私人令牌:https:
//gitlab.mycompany.com/profile/account
配置git以使用您的私有令牌添加额外标头:
$ git config --global http.extraheader "PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN
Run Code Online (Sandbox Code Playgroud)配置你的git将请求从ssh转换为http:
$ git config --global url."git@gitlab.mycompany.com:".insteadOf "https://gitlab.mycompany.com/"
Run Code Online (Sandbox Code Playgroud)最后你可以go get正常使用:
$ go get gitlab.com/company/private_repo
Run Code Online (Sandbox Code Playgroud)jol*_*vin 17
以上所有对我都不起作用。克隆 repo 工作正常,但我仍然遇到unrecognized import错误。
由于它代表 Go v1.13,我在文档中发现我们应该像这样使用GOPRIVATE env 变量:
$ GOPRIVATE=github.com/ORGANISATION_OR_USER_NAME go get -u github.com/ORGANISATION_OR_USER_NAME/REPO_NAME
Run Code Online (Sandbox Code Playgroud)
Mic*_*rks 16
对于使用私人 GitLabs 的人,这里有一个可能有帮助的片段:https ://gist.github.com/MicahParks/1ba2b19c39d1e5fccc3e892837b10e21
也贴在下面:
该go命令行工具需要能够从你的私人GitLab下载依赖,但需要authenticaiton。
这假设您的私人 GitLab 托管在privategitlab.company.com.
推荐使用以下环境变量:
export GO111MODULE=on
export GOPRIVATE=privategitlab.company.com
Run Code Online (Sandbox Code Playgroud)
以上几行可能最适合您的 shell 启动,例如~/.bashrc.
GO111MODULE=on告诉 Golang 命令行工具您正在使用模块。我还没有在私有 GitLab 上使用不使用 Golang 模块的项目对此进行测试。
GOPRIVATE=privategitlab.company.com 告诉 Golang 命令行工具不要将公共互联网资源用于列出的主机名(如公共模块代理)。
为了将来证明这些说明,请遵循GitLab 文档中的本指南。我知道read_apiGolang 命令行工具需要作用域才能工作,我也可能怀疑read_repository,但尚未证实这一点。
~/.netrc为了让 Golang 命令行工具向 GitLab 进行身份验证,~/.netrc最好使用文件。
如果文件不存在,要创建该文件,请运行以下命令:
touch ~/.netrc
chmod 600 ~/.netrc
Run Code Online (Sandbox Code Playgroud)
现在编辑文件的内容以匹配以下内容:
machine privategitlab.company.com login USERNAME_HERE password TOKEN_HERE
Run Code Online (Sandbox Code Playgroud)
WhereUSERNAME_HERE替换为您的 GitLab 用户名,TOKEN_HERE并替换为上一节中获取的访问令牌。
不要不设置与沿此线的东西一个全球性的git的配置:
machine privategitlab.company.com login USERNAME_HERE password TOKEN_HERE
Run Code Online (Sandbox Code Playgroud)
我相信在撰写本文时,Golang 命令行工具不完全支持 SSH git,这可能会导致与~/.netrc.
对于该git工具的常规使用,而不是 Golang 命令行工具,~/.ssh/config设置一个文件很方便。为此,请运行以下命令:
git config --global url."git@privategitlab.company.com:".insteadOf "https://privategitlab.company.com"
Run Code Online (Sandbox Code Playgroud)
请注意上面文件和目录的权限对于 SSH 在大多数 Linux 系统上的默认配置中工作是必不可少的。
然后,编辑~/.ssh/config文件以匹配以下内容:
Host privategitlab.company.com
Hostname privategitlab.company.com
User USERNAME_HERE
IdentityFile ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
请注意上述文件中的间距很重要,如果不正确将使文件无效。
USERNAME_HERE你的 GitLab 用户名在哪里,是你文件系统中~/.ssh/id_rsaSSH私钥的路径。你已经上传的公共密钥来GitLab。这里有一些说明。
这看起来像GitLab问题5769.
在GitLab中,由于存储库总是以结尾
.git,我必须.git在存储库名称的末尾指定使其工作,例如:Run Code Online (Sandbox Code Playgroud)import "example.org/myuser/mygorepo.git"和:
Run Code Online (Sandbox Code Playgroud)$ go get example.org/myuser/mygorepo.git看起来像GitHub通过追加来解决这个问题
".git".
它应该在" 添加对Go的存储库检索的支持 "中得到解决.#5958 ",前提是正确的meta标签.
虽然Go本身仍有问题:" cmd/go:get get无法在HTML5文档中发现元标记 ".
在此处生成 github oauth 令牌并将您的 github 令牌导出为环境变量:
export GITHUB_TOKEN=123
Run Code Online (Sandbox Code Playgroud)
设置 git config 以使用基本身份验证 URL:
git config --global url."https://$GITHUB_TOKEN:x-oauth-basic@github.com/".insteadOf "https://github.com/"
Run Code Online (Sandbox Code Playgroud)
现在您可以使用go get您的私人仓库。
我遇到.netrc并发现它与此相关。
创建一个~/.netrc包含以下内容的文件:
machine github.com
login <github username>
password <github password or Personal access tokens >
Run Code Online (Sandbox Code Playgroud)
完毕!
此外,对于最新的 GO 版本,您可能需要将其添加到环境变量中GOPRIVATE=github.com
(我已将其添加到我的.zshrc)
netrc 也使我的开发环境设置更好,因为我的个人 GitHub HTTPS 访问现在已配置为可在整个机器上使用(就像我的 SSH 配置一样)。
生成 GitHub 个人访问令牌:https : //github.com/settings/tokens
请参阅此答案以了解其在 Windows 上的 Git 使用情况
参考:netrc 手册页
如果您想坚持使用 SSH 身份验证,则屏蔽请求以强制使用 ssh
git config --global url."git@github.com:".insteadOf "https://github.com/"
更多设置git访问的方法:https : //gist.github.com/technoweenie/1072829#gistcomment-2979908
如果您已经使用SSH已经有了GIT中,这个答案由阿马尔Bandukwala是一个简单的解决方法:
$ go getgit内部使用。以下一线将制作git并因此$ go get通过SSH克隆您的软件包。
Github:
$ git config --global url."git@github.com:".insteadOf "https://github.com/"
Run Code Online (Sandbox Code Playgroud)
BitBucket:
$ git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"
Run Code Online (Sandbox Code Playgroud)
我创建了一个特定于用户的 ssh-config,因此我的用户会使用正确的凭据和密钥自动登录。
首先我需要生成一个密钥对
ssh-keygen -t rsa -b 4096 -C "my@email.here"
Run Code Online (Sandbox Code Playgroud)
并将其保存到例如~/.ssh/id_my_domain. 请注意,这也是我连接到 Github 帐户的密钥对(私有和公共),因此我的存储在~/.ssh/id_github_com.
然后我创建(或更改)了一个~/.ssh/config带有条目的文件:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_github_com
Run Code Online (Sandbox Code Playgroud)
在另一台服务器上,“ssh-url”是admin@domain.com:username/private-repo.git,该服务器的条目应该是:
Host domain.com
HostName domain.com
User admin
IdentityFile ~/.ssh/id_domain_com
Run Code Online (Sandbox Code Playgroud)
只是为了澄清您需要确保User,Host和HostName设置正确。
现在我可以浏览 go 路径,然后go get <package>,例如go get main文件main/main.go包含包的位置(来自上面的最后一个示例)domain.com:username/private-repo.git。
小智 5
在尝试了多种解决方案后,我的问题仍然存在。设置~/.netrcSSH 配置文件后的最终解决方案是将以下行添加到我的~/.bash_profile
export GOPRIVATE="github.com/[organization]"
| 归档时间: |
|
| 查看次数: |
70000 次 |
| 最近记录: |