go学习笔记:用vscode搭建go开发环境

发布 : 2017-04-11 分类 : Software 浏览 :

安装Go插件

20170411149189925767872.png

修改配置

command+,打开偏好设置

1
2
"go.gopath": "/Users/{user_name}/go",
"go.goroot": "/usr/local/opt/go/libexec"

安装 golang debug 插件 delve

1
brew install go-delve/delve/delve

否则使用vscode的调试功能的时候会报错:
Failed to continue: “Cannot find Delve debugger. Install from https://github.com/derekparker/delve & ensure it is in your “GOPATH/bin” or “PATH”.”

安装依赖

当vocode提示缺少以下依赖的时候,选择安装
若安装失败,在终端运行对应的命令

1
2
3
4
5
6
7
8
9
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
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

调试

调试 - 添加配置
20170411149189954583746.png

修改program为文件路径

/Users/jim/Documents/code/go/.vscode/launch.json
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "/Users/jim/go"
}
],
"compounds": []
}

开始调试:

20170411149189917370532.png

本文作者 : 小凡
原文链接 : https://16bh.github.io/2017/04/11/go-study-note-vscode/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
留下足迹