1. 使用VS Code安装GO环境
百度下载go安装包安装之后,比如我本地是安装在D:\program files\Go目录,此时需要将系统的环境变量更改为此目录,因为环境变量中默认填写的是C:\Users\Administrator\go,但是这个目录下并没有什么东西,导致在VS中运行的时候会报错。修改之后没生效可以试试重启电脑。
第一次运行的时候VS会提示下载GO的插件,默认的proxy设置是
GOPROXY=https://proxy.golang.org/
但是这个地址国内访问有问题,下载的时候会报错如:
Installing github.com/fatih/gomodifytags@latest FAILED
所以需要修改为:
GOPROXY=https://goproxy.io/
在windows的命令行中(cmd)进行修改,修改使用的命令为:
go env -w GOPROXY=https://goproxy.io/,direct
修改完成之后重启VS即可正常下载插件了,插件安装成功之后有如下提示:
Tools environment: GOPATH=D:\program files\Go
Installing 10 tools at D:\program files\Go\bin in module mode.
gopkgs
go-outline
gotests
gomodifytags
impl
goplay
dlv
dlv-dap
staticcheck
gopls
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest (D:\program files\Go\bin\gopkgs.exe) SUCCEEDED
Installing github.com/ramya-rao-a/go-outline@latest (D:\program files\Go\bin\go-outline.exe) SUCCEEDED
Installing github.com/cweill/gotests/gotests@latest (D:\program files\Go\bin\gotests.exe) SUCCEEDED
Installing github.com/fatih/gomodifytags@latest (D:\program files\Go\bin\gomodifytags.exe) SUCCEEDED
Installing github.com/josharian/impl@latest (D:\program files\Go\bin\impl.exe) SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay@latest (D:\program files\Go\bin\goplay.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@latest (D:\program files\Go\bin\dlv.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@master (D:\program files\Go\bin\dlv-dap.exe) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (D:\program files\Go\bin\staticcheck.exe) SUCCEEDED
Installing golang.org/x/tools/gopls@latest (D:\program files\Go\bin\gopls.exe) SUCCEEDED
All tools successfully installed. You are ready to Go. :)