Golang module拉取gitlab私有仓库

1、设置环境变量
1
2
echo 'export GOPRIVATE="gitlab.imind.tech"' >> ~/.zprofile  #mac系统,其他系统类似
source ~/.zprofile
2、设置git强制走ssh协议get私有包代码,并替换域名
1
git config --global url."git@gitlab.imind.tech:".insteadOf https://gitlab.imind.tech
3、git账号配置ssh秘钥
  1. 如果没有ssh秘钥,运行如下命令生成ssh公钥和私钥对

    1
    ssh-keygen -t rsa -C 'xxx@imind.tech' # -C 参数是你的邮箱地址
  2. 打开~/.ssh/id_rsa.pub,复制其中的内容

  3. 登录gitlab,在Edit profile -> SSH Keys 设置ssh秘钥

    image-20210620101955916

    将上一步复制的公钥内容粘贴到框3中,然后点击框4添加key

4、拉取私有仓库包
1
go get gitlab.imind.tech/micro/pkg@latest