Go Mod 添加私有仓库

  • 添加免密认证
# cat ~/.ssh/config
# gitlab
Host gitlab.xxx.com
Port 22
HostName gitlab.xxx.com
PreferredAuthentications publickey
IdentityFile your_private_key_path
User wangruixing

############

# 配置文件参数
# Host : 主机名/IP/域名
# HostName : 主机名/IP/域名(通常与Host一致)
# User : 登录名(如gitlab的username)
# IdentityFile : 私钥路径
# Port: ssh端口号

  • 配置git不以http方式拉取
git config --global url."git@gitlab.xxx.com:".insteadOf "https://gitlab.xxx.com"
  • 配置GoMod私有仓库
go env -w GOPRIVATE="git@gitlab.xxx.com"