jlzzjlzz亚洲乱熟在线播放

系統城裝機大師 - 固鎮縣祥瑞電腦科技銷售部宣傳站!

當前位置:首頁 > 腳本中心 > 其它 > 詳細頁面

VS Code安裝go插件失敗原因分析以及解決方案

時間:2022-09-12來源:www.farandoo.com作者:電腦系統城

問題背景

VSCode是我們開發go程序的常用工具,但是安裝VSCode成功后,創建一個.go文件會有如下提示:

這個是vscode提示你需要安裝go插件,但是當你點擊install all進行安裝時,發現會安裝失敗。

Installing 8 tools at D:\pragrams\go\bin
  gocode
  gopkgs
  go-outline
  go-symbols
  dlv
  godef
  goreturns
  golint
 
Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing github.com/derekparker/delve/cmd/dlv FAILED
Installing github.com/rogpeppe/godef FAILED
Installing github.com/sqs/goreturns FAILED
Installing golang.org/x/lint/golint FAILED
 
8 tools failed to install.
 
gocode:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/mdempsky/gocode
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/mdempsky/gocode: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/mdempsky/gocode: exec: "git": executable file not found in %PATH%
 
gopkgs:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/uudashr/gopkgs/cmd/gopkgs
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/uudashr/gopkgs/cmd/gopkgs: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/uudashr/gopkgs/cmd/gopkgs: exec: "git": executable file not found in %PATH%
 
go-outline:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/ramya-rao-a/go-outline
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/ramya-rao-a/go-outline: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/ramya-rao-a/go-outline: exec: "git": executable file not found in %PATH%
 
go-symbols:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/acroca/go-symbols
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/acroca/go-symbols: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/acroca/go-symbols: exec: "git": executable file not found in %PATH%
 
dlv:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/derekparker/delve/cmd/dlv
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/derekparker/delve/cmd/dlv: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/derekparker/delve/cmd/dlv: exec: "git": executable file not found in %PATH%
 
godef:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/rogpeppe/godef
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/rogpeppe/godef: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/rogpeppe/godef: exec: "git": executable file not found in %PATH%
 
goreturns:
Error: Command failed: D:\install\go\bin\go.exe get -u -v github.com/sqs/goreturns
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/sqs/goreturns: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/sqs/goreturns: exec: "git": executable file not found in %PATH%
 
golint:
Error: Command failed: D:\install\go\bin\go.exe get -u -v golang.org/x/lint/golint
go: missing Git command. See https://golang.org/s/gogetcmd
package golang.org/x/lint/golint: exec: "git": executable file not found in %PATH%
go: missing Git command. See https://golang.org/s/gogetcmd
package golang.org/x/lint/golint: exec: "git": executable file not found in %PATH%

問題原因

 在安裝go插件時,會自動更新很多依賴庫文件,都是從Github更新下來,但是因為Github的文件中,多有應用go官網中的文件,因為一些網絡國內無法訪問,網絡緣故,不能直接下載,導致安裝失敗。

解決方案

方案1:快速方案

核心是配置國內下載源,我們需要修改如下兩個go的環境配置:

1
2
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn

配置好兩個變量后,重新打開VSCode,點擊右下方的install all重新安裝,

或者,在vscode中使用Ctrl+Shift+P,輸入>go:install,下面會自動搜索相關命令,我們選擇Go:Install/Update Tools這個命令,選中所有插件,點擊確定進行安裝。

 

問題成功解決:

方案2:環境變量中配置

Windows在電腦 -> 系統 -> 高級系統設置 -> 用戶環境中分別新建GO111MODULE和GOPROXY兩個用戶變量,其值如下圖所示:

1
2
GO111MODULE=on
GOPROXY=https://goproxy.cn,direct

或者也可以使用阿里源代理如下:

1
2
GO111MODULE=on
GOPROXY=https://mirrors.aliyun.com/goproxy/  

配置好之后,使用Windows + R調出終端,輸入cmd,通過go env命令查看go的環境變量配置是否設置成功。 

方案3:vscode中配置

vscode編輯器的設置在:文件 -> 首選項 -> 設置 -> 用戶 -> 應用程序 -> 代理服務器路徑下,如下圖所示:

總結

到此這篇關于VS Code安裝go插件失敗原因分析以及解決方案的文章就介紹到這了

分享到:

相關信息

系統教程欄目

欄目熱門教程

人氣教程排行

站長推薦

熱門系統下載