Home >Backend Development >Golang >Explain how to install gitlab private packages with go get

Explain how to install gitlab private packages with go get

藏色散人
藏色散人forward
2022-01-06 15:29:163593browse

This article is summarized and introduced by the tutorial column of golang on how to install the gitlab private package with go get. I hope it will be helpful to friends in need!

  • Get the gitlab token

    Enter Gitlab—>Settings—>Access Tokens, and then create a personal access token. It is best to choose read-only (read_repository) for the permission here ).

  • Git configuration to add access token

After having the access token, we also need to configure it in git so that we can go get it. For private warehouse packages, you need to add the token just now to the git request header. The operation is as follows:

git config --global http.extraheader "PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN"
  • Configure git to convert the request from ssh to http
git config --global url."git@gitlab_url:groupName/projectName.git".insteadOf "https://gitlab_url/groupName/projectName.git"`

The above is to modify the configuration through commands. You can also directly modify the configuration file ~/.gitconfig like this, and add the following configuration in it:

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

Note: The parameter in insteadof is https, because the target address is ignored Is it http or https? Go get uses https access by default, so we have to forcefully convert https to git protocol

  • #If this still doesn't work, you need to set some environment variables of go Configure

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"

The above is the detailed content of Explain how to install gitlab private packages with go get. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete