歡迎您光臨本站 註冊首頁

成功安裝vscode中go的相關插件(詳細教程)

←手機掃碼閱讀     zhang3221994 @ 2020-06-03 , reply:0

讓你成功安裝vscode中go的相關插件  

注意:該演示環境是windows環境,linux和mac環境操作思路一樣

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

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

但是由於各種原因,這些插件無法安裝,甚至你翻牆之後發現也還是無法安裝,加上最近翻牆被限制的這麼嚴格,所以總結了如下方法,讓你在不翻牆的情況下還能將這些插件安裝成功,下圖是我直接通過vscode安裝提示的錯誤:

貌似運氣還不錯,還安裝成功了幾個,但是大部分還是沒有安裝成功,下面是詳細的安裝日誌:

 Installing 14 tools at D:go_projectin 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:Goingo.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:Goingo.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:Goingo.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:Goingo.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:Goingo.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:Goingo.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:Goingo.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:Goingo.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%srcgithub.comgolang

我這裡的GOPATH是在D:go_project
如果src目錄下面沒有github.comgolang請自行創建

完成目錄切換後,開始下載插件包:

git clone https://github.com/golang/tools.git tools

當下載完成後,你會發現%GOPATH%srcgithub.comgolang多了一個tools目錄
需要把tools目錄下的所有文件拷貝到%GOPATH%srcgolang.orgx ools下,如果沒有自行創建
當然如果你是windows環境,如果你當前是在%GOPATH%srcgolang.orgx ools
目錄下,你可以直接使用如下命令進行拷貝:
xcopy /s /e %GOPATH%srcgithub.comgolang ools
關於這個命令的使用可以具體百度查看,如果對該命令不熟悉就手動拷貝,直接將你下載的tools目錄下的所有文件拷貝到%GOPATH%srcgolang.orgx ools目錄下

經過多次測試,插件中有幾個其實不用翻牆或其他方法就可以安裝成功:

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開發需要安裝的插件都已經安裝成功


[zhang3221994 ] 成功安裝vscode中go的相關插件(詳細教程)已經有253次圍觀

http://coctec.com/docs/vscode/show-post-236756.html