Visual Studio Code 安装Go语言调试环境
之前我的电脑上已经安装好了Go,而且配置好了gopath,并运行了helloWorld。但在使用VSCode的时候,一保存源代码,就提示安装tools ,但是又因为网络的原因安装不了。导致我写代码的心情也没啦。
好在折腾了一番,问题解决了。解决的方法就是自己下载相应的文件放在对应的文件夹中,也可以使用git clone.这里以golint的安装为例,说明这种方法:
下载好golint :github链接
将它放在这个位置
1 | /Users/yiqiok/learngo/src/github.com/golang/lint |
这里我的gopath为:1
/Users/yiqiok/learngo
具体位置根据gopath而定。
接下来你可以试着执行:1
yiqiok:learngo yiqiok$ go get -u github.com/golang/lint/golint
要是成功了就小功告成了,不过一般会失败的:1
2yiqiok:learngo yiqiok$ go get -u github.com/golang/lint/golint
package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
这是找不到tools下面的文件。
从这里1
/Users/yiqiok/learngo/src/golang.org/x
执行git clone 命令:1
2
3
4
5
6
7yiqiok:x yiqiok$ git clone https://github.com/golang/tools.git
Cloning into 'tools'...
remote: Counting objects: 18444, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 18444 (delta 2), reused 13 (delta 2), pack-reused 18426
Receiving objects: 100% (18444/18444), 7.59 MiB | 58.00 KiB/s, done.
Resolving deltas: 100% (13177/13177), done.
然后再执行1
yiqiok:learngo yiqiok$ go get -u github.com/golang/lint/golint
golint就安装好啦。
其他的几个tools安装方法也一样。
- Blog Link: https://www.tbfeng.com/install-go-tools-for-visual-studio-code.html
- Copyright Declaration: The author owns the copyright, please indicate the source reproduced.