写go程序有时候会引到golang.org/x的包,下不下来就会飘红,go get也会失败,没研究过依赖处理,每回解决完就忘了,再遇到又得查,特记:
- goland 设置,file->Settings->Go->Go Modules ,勾选Enable Go modules integration,并在Enviroment一栏填新增GOPROXY:
Apply 保存退出。 - 如果还没有mod文件,需要先初始化
cd $projectdir
go mod init ./
go mod tidy
- 然后光标定位到飘红的依赖,Alt+enter键并在弹出菜单中选择sync dependencies即可