VScode安裝go外掛有個bug,即使上網姿勢科學也無法下載,安裝外掛會報錯如下
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.
這是因為go需要國內代理才能下載,Golang設定代理GOPROXY和GOSUMDB如下:
1、開啟代理支援:
go env -w GO111MODULE=auto
2、設定代理
go env -w GOPRIVATE=代理地址,direct //“direct” 為特殊指示符,用於指示 Go 回源到模組版本的源地址去抓取(比如 GitHub 等),當值列表中上一個 Go module proxy 返回 404 或 410 錯誤時,Go 自動嘗試列表中的下一個,遇見 “direct” 時回源,遇見 EOF 時終止並丟擲類似 “invalid version: unknown revision…” 的錯誤
golang外掛代理地址:
全球地址:
go env -w GOPROXY=https://proxy.golang.com.cn,direct
go env -w GOPROXY=https://goproxy.io,direct
go env -w GOSUMDB=gosum.io+ce6e7565+AY5qEHUk/qmHc5btzW45JVoENfazw8LielDsaI+lEbq6
go env -w GOSUMDB=sum.golang.google.cn
七牛雲:
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOSUMDB=goproxy.cn/sumdb/sum.golang.org
阿里雲:
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
# GOSUMDB 不支援
百度雲:
go env -w GOPROXY=https://goproxy.bj.bcebos.com/,direct
# 不支援 GOSUMDB
GoCenter
go env -w GOPROXY=https://gocenter.io,direct # 不支援 GOSUMDB
最後:關閉,重新開啟vscode,點選Install All即可完成安裝。
本作品採用《CC 協議》,轉載必須註明作者和本文連結