Golang配置私有仓库依赖

Golang配置私有仓库依赖,第1张

有些情况下,Golang项目所使用的部分中间件上传到gitlab上的私有仓库。在go项目中需要引用这些私有仓库的代码,需进行如下配置

1.配置GOPRIVATE环境变量

   go env -w GOPRIVATE=gitlab.xxx.com

2.gitlab上生成access token

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

3.git配置添加access token

   git config --global http.extraheader "PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN"

4.配置git将请求从ssh转换为http

 git config --global url."[email protected]:utils/utils_go.git".insteadOf "https://gitlab.xxx.com/utils/utils_go.git"`

5.手动拉取代码

  go get -u -v -insecure gitlab.xxx.com/utils/utils_go

6.在项目中执行 go mod vender同步以来代码库

7.修改项目代码

   经过上面的修改,在golang项目中就可以使用如下import

import (

    "context"

    "gitlab.xxx.com/utils/utils_go/db/mysqlconns"

    "gitlab.xxx.com/utils/utils_go/esl"

    "gitlab.xxx.com/utils/utils_go/kafka"

    "github.com/google/uuid"

)

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

原文地址: https://outofmemory.cn/langs/995698.html

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

发表评论

登录后才能评论

评论列表(0条)

保存