go mod 使用私有gitlab群组的解决办法

由于go对私有gitlab的仓库支持不好,得使用下面这些步骤

  • 设置git使用 ssh协议 git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/"

  • 添加ssh key 到gitlab

    1. ssh-keygen 会生成 id_rsa.pub
    2. cat ~/.ssh/id_rsa.pub 粘贴到gitlab 右上角头像 Setting -> SSH keys,或者打开链接https://gitlab.com/profile/keys
  • 修改 go.mod 添加 replace gitlab.com/YourGroup/SubGroup/Project => gitlab.com/YourGroup/SubGroup/Project.git master

  • 设置noproxy域名 go env -w GONOPROXY=\*\*.gitlab.com\*\*

  • 设置private域名 go env -w GOPRIVATE=\*\*.gitlab.com\*\*

自己搭建的gitlab也是如此