2

go get 安装gitlab私有包

 2 years ago
source link: https://studygolang.com/articles/35397
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

go get 安装gitlab私有包

hickey666 · 3天之前 · 153 次点击 · 预计阅读时间 1 分钟 · 大约8小时之前 开始浏览    
  • 获取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"

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK