gitlab 项目支持 go module

gitlab 项目支持 go module

有 2 个地方需要注意:

  • 个人访问令牌
  • 不支持 HTTPS 的 gitlab 网站

个人访问令牌

  • 这个网址内创建一个 http://gitlab.xxxx.com/profile/personal_access_tokens
  • 权限最好只读
  • 只有有人创建一个即可,所有人都可以使用这个
  • 使用 gitlab 项目的应用, go build 前加:
    git config http.extraheader "PRIVATE-TOKEN: [your private token]"
    

不支持 HTTPS 的 gitlab 网站

如果你的 gitlab 不支持 https ,需要 go build 前添加:

git config url."[email protected]/fananchong/test_go_module.git".insteadOf "http://gitlab.xxxx.com/fananchong/test_go_module.git"`
go get -v -insecure gitlab.xxxx.com/fananchong/[email protected]

完整的脚本例子

if "%1"=="init" (
    set GOPROXY=
    REM 设置`个人访问令牌`
    git config http.extraheader "PRIVATE-TOKEN: xxxxxxxxxxxxxxx"
    REM 如果 gitlab 网站支持 https ,下面这 2 行是不需要的
    REM 版本管理, go get 是加 @v2.0.0 ; gitlab 网站支持 https 的,则直接 go.mod 中改版本号为 v2.0.0
    git config url."[email protected]/fananchong/test_go_module.git".insteadOf "http://gitlab.xxxx.com/fananchong/test_go_module.git"`
    go get -v -insecure gitlab.xxxx.com/fananchong/[email protected]
) ^
else if "%1"=="build" (
    REM 设置代理,可以下载墙外包,如 golang/x 下的包等
    set GOPROXY=https://goproxy.io
    set GOBIN=%~dp0bin
    go install ./...
)
发布了129 篇原创文章 · 获赞 73 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/u013272009/article/details/96012659