VS Code无法安装Go扩展依赖包问题解决及剖析 您所在的位置:网站首页 支持opengles31扩展包怎么解决 VS Code无法安装Go扩展依赖包问题解决及剖析

VS Code无法安装Go扩展依赖包问题解决及剖析

2023-11-16 08:42| 来源: 网络整理| 查看: 265

问题:

    在家里按照之前自己写的一篇博客”Go语言开发环境搭建详细教程“进行go语言的开发环境搭建时,发现安装go语言拓展的依赖包时出现错误了,具体错误如下(由于详细错误信息过长,所以下面只截取了部分关键错误信息):

Installing 8 tools at D:\GoProjects\bin

gocode

go-outline

go-symbols

guru

gorename

gocode-gomod

goreturns

golint

 

Installing github.com/mdempsky/gocode FAILED

Installing github.com/ramya-rao-a/go-outline FAILED

Installing github.com/acroca/go-symbols FAILED

Installing golang.org/x/tools/cmd/guru FAILED

Installing golang.org/x/tools/cmd/gorename FAILED

Installing github.com/stamblerre/gocode FAILED

Installing github.com/sqs/goreturns FAILED

Installing golang.org/x/lint/golint FAILED

 

8 tools failed to install.

 

gocode:

Error: Command failed: C:\Go\bin\go.exe get -u -v github.com/mdempsky/gocode

github.com/mdempsky/gocode (download)

Fetching https://golang.org/x/tools/go/gcexportdata?go-get=1

https fetch failed: Get https://golang.org/x/tools/go/gcexportdata?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.

 

gocode-gomod:

Error: Command failed: C:\Go\bin\go.exe get -u -v -d github.com/stamblerre/gocode

github.com/stamblerre/gocode (download)

Fetching https://golang.org/x/tools/go/packages?go-get=1

https fetch failed: Get https://golang.org/x/tools/go/packages?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.

 

golint:

Error: Command failed: C:\Go\bin\go.exe get -u -v golang.org/x/lint/golint

Fetching https://golang.org/x/lint/golint?go-get=1

https fetch failed: Get https://golang.org/x/lint/golint?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.

 

原因分析:

    根据以上错误信息可以得知,安装gocode和gocode-gomod需要依赖于https://golang.org/x/tools,安装golint需要依赖于https://golang.org/x/lint。但是由于我家里的网络无法访问Go官网(https://golang.org),所以最终导致了依赖包的安装失败。

 

如何解决? 1、购买vpn,使家里的网络可以访问https://golang.org,然后再进行安装 2、使用golang的镜像仓库

步骤一:查找镜像仓库源

    通过网上查阅资料得知,golang 在 github 上建立了一个镜像库,如:https://golang.org/x/net 的镜像库,在GitHub上对应的是https://github.com/golang/net。果然,我在https://github.com/golang镜像仓库上找到了安装所需的依赖包https://github.com/golang/tools和https://github.com/golang/lint

 

步骤二:获取镜像仓库

    通过查看公司正常安装了依赖包的GOPATH目录得知,从golang获取的源码存储于D:\GoProjects\src\golang.org\x\目录下面,因此相应的https://golang.org/x/tools和https://golang.org/x/lint的源码也应该存储在对应GOPATH目录下。接下来打开终端command +R,输入cmd回车,通过以下命令进行源码的获取:

注意:以下均根据我本地设置的GOPATH进行操作,读者实际操作时需要根据VS Code设置的GOPATH进行相应的修改。

// 进入VS Code设置的GOPATH的src目录 cd /D D:\GoProjects\src // 创建golang.org目录,如果已经存在忽略该指令 mkdir golang.org // 进入golang.org目录 cd golang.org // 创建x目录,如果已经存在忽略该指令 mkdir x // 进入x目录 cd x // 获取tools源码 git clone https://github.com/golang/tools // 获取lint源码 git clone https://github.com/golang/lint

 

步骤三:重新安装

    重新触发安装go语言扩展提示,并点击install all重新安装,关于如何重新触发安装提示可以参照“Go语言开发环境搭建详细教程”。安装成功后,将得到以下提示:

Installing github.com/mdempsky/gocode SUCCEEDED

Installing github.com/ramya-rao-a/go-outline SUCCEEDED

Installing github.com/acroca/go-symbols SUCCEEDED

Installing golang.org/x/tools/cmd/guru SUCCEEDED

Installing golang.org/x/tools/cmd/gorename SUCCEEDED

Installing github.com/stamblerre/gocode SUCCEEDED

Installing github.com/sqs/goreturns SUCCEEDED

Installing golang.org/x/lint/golint SUCCEEDED

 

All tools successfully installed. You're ready to Go :).

 

问题衍生:

    至此,我们已经成功解决了VS Code 无法安装Go语言扩展依赖包的问题。通过对问题的分析,实际上我们解决的最终问题是“go get 无法下载golang官网语言包”的问题,所以日后如果遇到无法下载golang官网语言包的问题,也可以通过“使用golang的镜像仓库“的方式进行解决。

 

 

 

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有