欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

成功安装vscode中go的相关插件(详细教程)

程序员文章站 2022-03-12 11:25:26
让你成功安装vscode中go的相关插件注意:该演示环境是windows环境,linux和mac环境操作思路一样vscode中有很多go的相关插件,非常好用如下:gocodegopkgsgo-outl...

让你成功安装vscode中go的相关插件

注意:该演示环境是windows环境,linux和mac环境操作思路一样

vscode中有很多go的相关插件,非常好用如下:

gocode
gopkgs
go-outline
go-symbols
guru
gorename
gomodifytags
goplay
impl
godef
goreturns
golint
gotests
dlv

但是由于各种原因,这些插件无法安装,甚至你*之后发现也还是无法安装,加上最近*被限制的这么严格,所以总结了如下方法,让你在不*的情况下还能将这些插件安装成功,下图是我直接通过vscode安装提示的错误:

成功安装vscode中go的相关插件(详细教程)

貌似运气还不错,还安装成功了几个,但是大部分还是没有安装成功,下面是详细的安装日志:

installing 14 tools at d:\go_project\bin
 gocode
 gopkgs
 go-outline
 go-symbols
 guru
 gorename
 gomodifytags
 goplay
 impl
 godef
 goreturns
 golint
 gotests
 dlv

installing github.com/nsf/gocode succeeded
installing github.com/uudashr/gopkgs/cmd/gopkgs succeeded
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/fatih/gomodifytags succeeded
installing github.com/haya14busa/goplay/cmd/goplay succeeded
installing github.com/josharian/impl failed
installing github.com/rogpeppe/godef succeeded
installing sourcegraph.com/sqs/goreturns failed
installing github.com/golang/lint/golint failed
installing github.com/cweill/gotests/... failed
installing github.com/derekparker/delve/cmd/dlv succeeded

8 tools failed to install.

go-outline:
error: command failed: d:\go\bin\go.exe get -u -v github.com/ramya-rao-a/go-outline
github.com/ramya-rao-a/go-outline (download)
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.)
github.com/ramya-rao-a/go-outline (download)
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.)

go-symbols:
error: command failed: d:\go\bin\go.exe get -u -v github.com/acroca/go-symbols
github.com/acroca/go-symbols (download)
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.)
github.com/acroca/go-symbols (download)
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.)

guru:
error: command failed: d:\go\bin\go.exe get -u -v golang.org/x/tools/cmd/guru
fetching https://golang.org/x/tools/cmd/guru?go-get=1
https fetch failed: get https://golang.org/x/tools/cmd/guru?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/cmd/guru: unrecognized import path "golang.org/x/tools/cmd/guru" (https fetch: get https://golang.org/x/tools/cmd/guru?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.)
fetching https://golang.org/x/tools/cmd/guru?go-get=1
https fetch failed: get https://golang.org/x/tools/cmd/guru?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/cmd/guru: unrecognized import path "golang.org/x/tools/cmd/guru" (https fetch: get https://golang.org/x/tools/cmd/guru?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.)

gorename:
error: command failed: d:\go\bin\go.exe get -u -v golang.org/x/tools/cmd/gorename
fetching https://golang.org/x/tools/cmd/gorename?go-get=1
https fetch failed: get https://golang.org/x/tools/cmd/gorename?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/cmd/gorename: unrecognized import path "golang.org/x/tools/cmd/gorename" (https fetch: get https://golang.org/x/tools/cmd/gorename?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.)
fetching https://golang.org/x/tools/cmd/gorename?go-get=1
https fetch failed: get https://golang.org/x/tools/cmd/gorename?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/cmd/gorename: unrecognized import path "golang.org/x/tools/cmd/gorename" (https fetch: get https://golang.org/x/tools/cmd/gorename?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.)

impl:
error: command failed: d:\go\bin\go.exe get -u -v github.com/josharian/impl
github.com/josharian/impl (download)
fetching https://golang.org/x/tools/imports?go-get=1
https fetch failed: get https://golang.org/x/tools/imports?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/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: get https://golang.org/x/tools/imports?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.)
github.com/josharian/impl (download)
fetching https://golang.org/x/tools/imports?go-get=1
https fetch failed: get https://golang.org/x/tools/imports?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/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: get https://golang.org/x/tools/imports?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.)

goreturns:
error: command failed: d:\go\bin\go.exe get -u -v sourcegraph.com/sqs/goreturns
fetching https://sourcegraph.com/sqs/goreturns?go-get=1
parsing meta tags from https://sourcegraph.com/sqs/goreturns?go-get=1 (status code 200)
get "sourcegraph.com/sqs/goreturns": found meta tag get.metaimport{prefix:"sourcegraph.com/sqs/goreturns", vcs:"git", reporoot:"https://github.com/sqs/goreturns"} at https://sourcegraph.com/sqs/goreturns?go-get=1
sourcegraph.com/sqs/goreturns (download)
github.com/sqs/goreturns (download)
fetching https://golang.org/x/tools/imports?go-get=1
https fetch failed: get https://golang.org/x/tools/imports?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/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: get https://golang.org/x/tools/imports?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.)
fetching https://sourcegraph.com/sqs/goreturns?go-get=1
parsing meta tags from https://sourcegraph.com/sqs/goreturns?go-get=1 (status code 200)
get "sourcegraph.com/sqs/goreturns": found meta tag get.metaimport{prefix:"sourcegraph.com/sqs/goreturns", vcs:"git", reporoot:"https://github.com/sqs/goreturns"} at https://sourcegraph.com/sqs/goreturns?go-get=1
sourcegraph.com/sqs/goreturns (download)
github.com/sqs/goreturns (download)
fetching https://golang.org/x/tools/imports?go-get=1
https fetch failed: get https://golang.org/x/tools/imports?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/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: get https://golang.org/x/tools/imports?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: d:\go\bin\go.exe get -u -v github.com/golang/lint/golint
github.com/golang/lint (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.
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: 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.)
github.com/golang/lint (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.
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: 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.)

gotests:
error: command failed: d:\go\bin\go.exe get -u -v github.com/cweill/gotests/...
github.com/cweill/gotests (download)
fetching https://golang.org/x/tools/imports?go-get=1
https fetch failed: get https://golang.org/x/tools/imports?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 github.com/cweill/gotests
 imports golang.org/x/tools/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: get https://golang.org/x/tools/imports?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.)
github.com/cweill/gotests (download)
fetching https://golang.org/x/tools/imports?go-get=1
https fetch failed: get https://golang.org/x/tools/imports?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 github.com/cweill/gotests
 imports golang.org/x/tools/imports: unrecognized import path "golang.org/x/tools/imports" (https fetch: get https://golang.org/x/tools/imports?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.)

其实去src目录下看的话,是下载成功了,但是没有安装成功,并且我们也可以看出有几个是可以直接安装成功的

github.com/nsf/gocode
github.com/tpng/gopkgs
github.com/fatih/gomodifytags
github.com/haya14busa/goplay
github.com/rogpeppe/gode
github.com/derekparker/delve/cmd/dlv

解决方法

关于go开发目录的结构这里不做过多解释,之前已经说过了

进行如下命令进行目录切换:

cd %gopath%\src\github.com\golang

我这里的gopath是在d:\go_project
如果src目录下面没有github.com\golang请自行创建

完成目录切换后,开始下载插件包:

git clonetools

当下载完成后,你会发现%gopath%\src\github.com\golang多了一个tools目录
需要把tools目录下的所有文件拷贝到%gopath%\src\golang.org\x\tools下,如果没有自行创建
当然如果你是windows环境,如果你当前是在%gopath%\src\golang.org\x\tools
目录下,你可以直接使用如下命令进行拷贝:
xcopy /s /e %gopath%\src\github.com\golang\tools
关于这个命令的使用可以具体百度查看,如果对该命令不熟悉就手动拷贝,直接将你下载的tools目录下的所有文件拷贝到%gopath%\src\golang.org\x\tools目录下

经过多次测试,插件中有几个其实不用*或其他方法就可以安装成功:

github.com/nsf/gocode
github.com/uudashr/gopkgs/cmd/gopkgs
github.com/fatih/gomodifytags
github.com/haya14busa/goplay/cmd/goplay
github.com/derekparker/delve/cmd/dlv

下面安装无法安装的插件
开始安装:
切换到gopath目录下,执行相关的go install 命令

go install github.com/ramya-rao-a/go-outline

go install github.com/acroca/go-symbols

go install golang.org/x/tools/cmd/guru

go install golang.org/x/tools/cmd/gorename

go install github.com/josharian/impl

go install github.com/rogpeppe/godef

go install github.com/sqs/goreturns

go install github.com/golang/lint/golint

go install github.com/cweill/gotests/gotests

这样vscode下go开发需要安装的插件都已经安装成功

总结

到此这篇关于成功安装vscode中go的相关插件的详细教程的文章就介绍到这了,更多相关vscode安装go插件内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!