记录一下解决vscode安装go插件失败问题

go安装这里就不讲解了,请看: [go学习笔记.第二章] 2.go语言的开发工具以及安装和配置SDK,这里讲解一下在使用vscode的时候,右下脚经常会弹出一个 install 的go插件,如下:
记录一下解决vscode安装go插件失败问题_第1张图片
这时点击install进行安装,有时候会报错:
gocode-gomod: failed to install gocode-gomod(github.com/stamblerre/[email protected]): Error: Command failed: /opt/go/bin/go get -x -d github.com/stamblerre/[email protected]
...
Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
...

解决办法:

执行下面两条命令
# 旧版,已废弃
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
# 新版改成如下链接
go env -w GO111MODULE=on
go env -w GOPROXY=https://proxy.golang.com.cn,direct
然后 关闭vscode重新打开,再次点击install
Tools environment: GOPATH=/var/www/go/projects
Installing 3 tools at /var/www/go/projects/bin in module mode.
  dlv
  staticcheck
  gopls

Installing github.com/go-delve/delve/cmd/dlv@latest (/var/www/go/projects/bin/dlv) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (/var/www/go/projects/bin/staticcheck) SUCCEEDED
Installing golang.org/x/tools/gopls@latest (/var/www/go/projects/bin/gopls) SUCCEEDED

All tools successfully installed. You are ready to Go. :)

安装成功

你可能感兴趣的:(golang,vscode,golang,ide)