一键配置脚本

#!/bin/bash

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=git.arsyun.com
go env -w GOINSECURE=git.arsyun.com

git config --global --add url."git@git.arsyun.com:".insteadOf "<http://git.arsyun.com/>"

# 然后配置 gitlab 里的 ssh 公私钥

# 体验一下
go get git.arsyun.com/hos-device/go-srv-device-logcollector@5b6efee

旧项目如何迁移到 go mod

  1. 脚本替换 module 引用方式(更新 module 名字,更新 module 引用名字)
#!/bin/bash

declare -a groups=(hos hos-device hos-disk)
for x in ${groups[@]}; do
    echo $x
    sed -i "s,\\"$x/,\\"git.arsyun.com/$x/,g" **/*.go
    sed -i "s,\\"$x/,\\"git.arsyun.com/$x/,g" go.mod
done
  1. go build ./... 验证是否完成迁移,如果出现小问题手动修复

参考