Gogland 是 JetBrains 公司推出的 Go 语言集成开发环境。Gogland 一样基于 IntelliJ 平台开发,支持 JetBrains 的插件体系。官方:https://www.jetbrains.com/go/。关于 Goland 相关配置参考该连接便可。Goland 用的好好的,为啥忽然想用到 VSCode 呢 ?VSCode 是目前比较流行的 IDE 工具,在功能方面也相对齐全,使用方面也比较友好。不过对于 Golang 来讲,配置起来不算太麻烦,只能说其中有一些比较坑的地方,今天咱们也就是来填坑的(该死的天朝网络,要否则也不用这么费劲了)。html
1、Golang 环境配置git
关于 Goland 的系统环境配置,这里就不在过多讲解,能够直接参考该连接的前半部分便可。github
2、安装配置 VSCodegolang
下载连接:https://code.visualstudio.com/网络
选择本身系统对应的版本就能够,这个作 IT 的都不知道那就转行吧。tcp
2.1 安装 golang 插件工具
进入Visual Studio Code,使用快捷键F1,打开命令面板测试
在上图光标处·输入 exten ,而后选择“Extensions:Install Extension”,以下图fetch
查询并安装 Go 插件ui
提示:在插件列表中,选择 Go,进行安装,安装以后,系统会提示重启Visual Studio Code。因为我这里已经安装过了,因此不会出现 "Install" 选项。
2.2 开启自动保存功能
打开Visual Studio Code,找到菜单File -> Preferences -> Settings,以下图:
选中 "User Settings" 配置以下内容
{ "files.autoSave": "onFocusChange", "editor.fontSize": 18, "go.goroot": "D:\\Go", "go.gopath": "D:\\Golang\\MyGO" }
其余保持默认配置便可;
2.3 执行相关命令(自行安装好git)
更多详细信息参考:https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go
1)安装gocode
打开命令提示符(以管理员身份打开),输入:
go get -u -v github.com/nsf/gocode
2)安装godef
go get -u -v github.com/rogpeppe/godef
3)安装golint
# 建立 $GOPATH/src/golang.org/x cd $GOPATH/src/golang.org/x git clone https://github.com/golang/tools.git git clone https://github.com/golang/lint.git # 完成以上步骤后,执行 go get golang.org/x/lint/golint
若是你遇到了相似以下错误,就能够经过 git clone 的方式把包下载到本地,再进行安装便可解决问题;
Fetching https://golang.org/x/tools/go/buildutil?go-get=1 https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. package golang.org/x/tools/go/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
4)安装go-find-references
go get -u -v github.com/lukehoban/go-find-references
5)安装go-outline
go get -u -v github.com/lukehoban/go-outline
6)安装goreturns
go get -u -v sourcegraph.com/sqs/goreturns
7)安装gorename
go get -u -v golang.org/x/tools/cmd/gorename
提示:若是还提示报错,由于前面已经git clone 下来了,能够执行执行"go install golang.org/x/tools/cmd/gorename";
8)安装gopkgs
go get -u -v github.com/tpng/gopkgs
9)安装go-symbols
go get -u -v github.com/newhook/go-symbols
2.4 写一个程序进行测试
能够看到可以进行相关提示。这里咱们执行完整程序测试一下,程序是否正常。
OK,彻底没有问题了。