讲解go get如何安装gitlab私有包

讲解go get如何安装gitlab私有包,第1张

讲解go get如何安装gitlab私有包 本文由golang教程栏目给大家总结介绍go get怎么安装gitlab私有包,希望对需要的朋友有所帮助!

  • 获取gitlab的token

    进入Gitlab—>Settings—>Access Tokens,然后创建一个personal access token,这里权限最好选择只读(read_repository)。

  • git配置添加access token

有了access token后,我们还需要在git中进行配置,这样才能go get下了私有仓库的包,需要把刚刚的token添加进git的请求头中, *** 作如下:

git config --global http.extraheader "PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN"
  • 配置git将请求从ssh转换为http
git config --global url."git@gitlab_url:groupName/projectName.git".insteadOf "https://gitlab_url/groupName/projectName.git"`

上面是通过命令修改配置,也可以像这样,直接修改配置文件 ~/.gitconfig,在里面添加如下配置:

[url "git@{{gitlab_url}}:"]
        insteadOf = https://{{gitlab_url}}/

注意:insteadof 中的参数是https,因为不管目标地址是http还是https,go get默认使用https方式访问,因此我们要强制将https转换成git协议

  • 如果这样还拉不下来,就需要对go的一些环境变量进行配置
Bash (Liunx or macOS)
# 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io,direct

# 还可以设置不走 proxy 的私有仓库或组,多个用逗号相隔(可选)
export GOPRIVATE=git.mycompany.com,github.com/my/private
Powerbash (Windows)
# 配置 GOPROXY 环境变量
$env:GOPROXY = "https://goproxy.io,direct"

# 还可以设置不走 proxy 的私有仓库或组,多个用逗号相隔(可选)
$env:GOPRIVATE = "git.mycompany.com,github.com/my/private"

以上就是讲解go get如何安装gitlab私有包的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/682364.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存