使用go mod tidy更新依赖包时,若出现报错,具体报错如下图所示:
可通过以上方式进行解决,具体步骤为:
1. windos环境中进入powershell
2. 设置环境变量 go env -w GO111MODULE=on
3. 添加代理,国内下载go的一些依赖需要添加代理,具体命令为:
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy,direct
若是在linux下出现上述错误,在命令行直接运行export GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy,direct
,就可解决上述问题。