配置private git仓库 使用ssh协议拉取go.mod包
默认私有仓库的依赖(例如公司内部gitlab仓库)是无法用go get(go get 默认走http方法)拉取到的,
假设私有仓库的hostname为:http://git.mycompany.net
需要做如下配置:
运行命令
git config --global url."git@git.mycompany.net:".insteadOf "https://git.mycompany.net/"
对于mac,运行命令
echo "GOPRIVATE=git.mycompany.net" >> ~/.bash_profile
对于ubuntu,运行命令
echo "GOPRIVATE=git.mycompany.net" >> ~/.bash_rc
说明:
配置git,访问http://git.mycompany.net时使用ssh协议(而不是https),从而获得ssh私钥提供的身份信息。
否则会因为缺失身份信息而无法拉取依赖。
配置GOPRIVATE环境变量,标记域名http://git.mycompany.net的包属于私有仓库,不做module的sum校验,否则拉取私有库会失败。
set GOPRIVATE=http://git.mycompany.net/*
set GONOPROXY=http://git.mycompany.net/*
set GONOSUMDB=http://git.mycompany.net/*