Explain how to install gitlab private packages with go get

藏色散人
Release: 2022-01-06 15:29:34
forward
3530 people have browsed it

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"
Copy after login
  • 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"`
Copy after login

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}}/
Copy after login

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
Copy after login

Powerbash (Windows)

# 配置 GOPROXY 环境变量
$env:GOPROXY = "https://goproxy.io,direct"

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

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template