如果你使用golang,那么强烈建议你采用vscode作为IDE。
1. 首先在vscode 当中安装go插件,如上图
2. 配置 %AppData%CodeUsersettings.json 当中的参数
go.goroot; go.toolsGopath 这两个参数一定要配置上
vscode配置有两种user,workspace
user是全局生效,针对所有项目
workspace仅针对当前项目,如果与user当中的配置不一样,在当前项目中使用workspace的配置
"go.formatTool": "goformat",
"go.goroot": "D:\sdk\go",
"go.toolsGopath": "D:\sdk\gotools",
"go.inferGopath": true,
"go.gotoSymbol.includeGoroot": true,
"go.gotoSymbol.includeImports": true,
"go.useLanguageServer": true,
"go.autocompleteUnimportedPackages": true,
"go.coverOnTestPackage": false,
将上面的配置增加到 settings.json 当中,然后重启vscode
3. ctrl+shift+p 调出go的命令窗口,然后选择 Go: Install/Update tools
为什么一定要安装这些工具呢?
没有这些工具,代码导航、格式化等这些常用功能都不能用,开发的效率和体验会非常不好
4. 选中所有的工具后,点击OK按钮
5. 等待下载安装完成即可
错误处理:
Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/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
国内特殊环境引起的,需要自行解决!
不过,在golang的最新版本中支持使用代理,使用方法如下
go env -w GOPROXY=https://goproxy.io,direct
如果全部成功将显示下面的提示:
Installing github.com/mdempsky/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED
Installing github.com/ramya-rao-a/go-outline SUCCEEDED
Installing github.com/acroca/go-symbols SUCCEEDED
Installing golang.org/x/tools/cmd/guru SUCCEEDED
Installing golang.org/x/tools/cmd/gorename SUCCEEDED
Installing github.com/cweill/gotests/... SUCCEEDED
Installing github.com/fatih/gomodifytags SUCCEEDED
Installing github.com/josharian/impl SUCCEEDED
Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED
Installing github.com/godoctor/godoctor SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode SUCCEEDED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing winterdrache.de/goformat/goformat SUCCEEDED
Installing golang.org/x/lint/golint SUCCEEDED
Installing golang.org/x/tools/gopls SUCCEEDED
Reload VS Code window to use the Go language server
All tools successfully installed. You're ready to Go :).