win10中,vscode安装go插件排雷指南

最近学习go,想着使用强大的vscode编写go,在安装go插件过程中,遇到了很多问题。下面记录解决方案。 

1)win10环境,安装go,vscode,git

配置GOPATH环境变量,在我的电脑->属性->高级系统设置->环境变量,新建GOPATH,

安装go之后,在cmd中输入go env查看go的环境配置。

2)vscode安装go插件。

安装插件依赖一直出错,显示 

go install github.com/golang/lint/golint
can't load package: package github.com/golang/lint/golint: code in directory G:\Go\Development\src\github.com\golang\lint\golint expects import "golang.org/x/lint/golint"

其他依赖插件还有goreturn安装错误。

  • 我使用ping命令,查看网络连接。
ping github.com

发现连接超时,但是连接其他baidu.com是正常的。

然后查看了很多解决方案, 

解决vscode中golang插件依赖安装失败问题

https://www.cnblogs.com/liangjf/p/9583057.html

【已解决】git clone出错:Failed to connect to github.com port 443 Operation timed out

有说法是需要FQ,发现也无法解决问题。

  • 直到看到下面的解决方案。

https://github.com/donnol/gox

https://gocn.vip/question/1877

但是不能完全按照上面的方案,还是出现个别插件无法安装。

最终解决方法:

1)

Administrator@PC-20170929IHOM MINGW64 /g/Go/Development (master)
$ git clone https://github.com/donnol/gox

2)

Administrator@PC-20170929IHOM MINGW64 /g/Go/Development (master)
$ cd gox/

3)

Administrator@PC-20170929IHOM MINGW64 /g/Go/Development/gox (master)
$ go build

4)

Administrator@PC-20170929IHOM MINGW64 /g/Go/Development/gox (master)
$ ./gox.exe

5)提示有错误

package github.com/golang/lint/golint: code in directory G:\Go\Development\src\github.com\golang\lint\golint expects import "golang.org/x/lint/golint"
=== download github.com/golang/lint/golint failed, err: exit status 1

解决方法:

进入GOPATH目录。

 新建目录src/golang.org/x/。

进入该目录,将失败插件git手动下载下来。

Administrator@PC-20170929IHOM MINGW64 /g/Go/Development/src/golang.org/x (master)
$ git clone https://github.com/golang/lint

然后回到GOPATH目录,我的是/g/Go/Development/

然后执行:go install golang.org/x/lint/golint。这里是手动安装上面下载夏利的golint,而不是像网络其他人的那样,安装github.com的命令,这里很关键!!

Administrator@PC-20170929IHOM MINGW64 /g/Go/Development (master)
$ go install golang.org/x/lint/golint
 

OK!!

 

猜你喜欢

转载自www.cnblogs.com/dingxiaoqiang/p/10874326.html