Go开发工具
本篇介绍主要介绍VSCODE,其他开发工具可参考Go开发工具;
Visual Studio Code(VSCODE)
vscode是微软基于Electron和web技术构建的开源编辑器,是一款很强大的编辑器,开源地址:https://github.com/Microsoft/vscode
1. 安装Vscode最新版
官网:https://code.visualstudio.com/ 下载最新版;
2. 安装Go插件
点击右边的 Extensions 图标 搜索Go插件 在插件列表中,选择 Go,进行安装,安装之后,系统会提示重启 Visual Studio Code;
建议把自动保存功能开启。开启方法为:选择菜单 File,点击 Auto save;
vscode代码设置可用于Go扩展。这些都可以在用户的喜好来设置或工作区设置(.vscode/settings.json);
打开首选项-用户设置 settings.json:
{
"go.buildOnSave": true,
"go.lintOnSave": true,
"go.vetOnSave": true,
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave": false,
"go.useCodeSnippetsOnFunctionSuggest": false,
"go.formatOnSave": true,
//goimports
"go.formatTool": "goreturns",
"go.goroot": "", //Your_Goroot
"go.gopath": "", //Your_Gopath
}
接着安装依赖包支持(网络不稳定,请直接到 GitHub Golang 下载再移动到相关目录):
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/zmb3/gogetdoc
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/cweill/gotests/...
vscode还有一项很强大的功能就是断点调试,结合delve可以很好的进行Go代码调试
```
go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
brew install go-delve/delve/delve(mac可选)
注意:修改”dlv-cert”证书,选择”显示简介”->”信任”->”代码签名”修改为:始终信任;
打开首选项-工作区设置,配置launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "main.go",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}", //工作空间路径
"env": {},
"args": [],
"showLog": true
}
]
}
```