今天打算学习一下 Go,在安装完VS Code 后,编写第一个go程序保存代码时,IDE 提示如下错误:
点击 install all
按钮安装这些扩展时,报错:
Installing 9 tools at /var/www/go/bin in module mode.
go-outline
gotests
gomodifytags
impl
goplay
dlv
staticcheck
gopls
goimports
Installing github.com/ramya-rao-a/go-outline@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v github.com/ramya-rao-a/go-outline@latest",
"stdout": "",
"stderr": "go: github.com/ramya-rao-a/go-outline@latest: module github.com/ramya-rao-a/go-outline: Get \"https://proxy.golang.org/github.com/ramya-rao-a/go-outline/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing github.com/cweill/gotests/gotests@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v github.com/cweill/gotests/gotests@latest",
"stdout": "",
"stderr": "go: github.com/cweill/gotests/gotests@latest: module github.com/cweill/gotests/gotests: Get \"https://proxy.golang.org/github.com/cweill/gotests/gotests/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing github.com/fatih/gomodifytags@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v github.com/fatih/gomodifytags@latest",
"stdout": "",
"stderr": "go: github.com/fatih/gomodifytags@latest: module github.com/fatih/gomodifytags: Get \"https://proxy.golang.org/github.com/fatih/gomodifytags/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing github.com/josharian/impl@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v github.com/josharian/impl@latest",
"stdout": "",
"stderr": "go: github.com/josharian/impl@latest: module github.com/josharian/impl: Get \"https://proxy.golang.org/github.com/josharian/impl/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing github.com/haya14busa/goplay/cmd/goplay@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v github.com/haya14busa/goplay/cmd/goplay@latest",
"stdout": "",
"stderr": "go: github.com/haya14busa/goplay/cmd/goplay@latest: module github.com/haya14busa/goplay/cmd/goplay: Get \"https://proxy.golang.org/github.com/haya14busa/goplay/cmd/goplay/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing github.com/go-delve/delve/cmd/dlv@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v github.com/go-delve/delve/cmd/dlv@latest",
"stdout": "",
"stderr": "go: github.com/go-delve/delve/cmd/dlv@latest: module github.com/go-delve/delve/cmd/dlv: Get \"https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing honnef.co/go/tools/cmd/staticcheck@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v honnef.co/go/tools/cmd/staticcheck@latest",
"stdout": "",
"stderr": "go: honnef.co/go/tools/cmd/staticcheck@latest: module honnef.co/go/tools/cmd/staticcheck: Get \"https://proxy.golang.org/honnef.co/go/tools/cmd/staticcheck/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing golang.org/x/tools/gopls@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v golang.org/x/tools/gopls@latest",
"stdout": "",
"stderr": "go: golang.org/x/tools/gopls@latest: module golang.org/x/tools/gopls: Get \"https://proxy.golang.org/golang.org/x/tools/gopls/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
Installing golang.org/x/tools/cmd/goimports@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "/usr/local/go/bin/go install -v golang.org/x/tools/cmd/goimports@latest",
"stdout": "",
"stderr": "go: golang.org/x/tools/cmd/goimports@latest: module golang.org/x/tools/cmd/goimports: Get \"https://proxy.golang.org/golang.org/x/tools/cmd/goimports/@v/list\": dial tcp 142.251.42.241:443: i/o timeout\n"
}
9 tools failed to install.
失败原因
golang.org 在国内由于一些众所周知的原因无法直接访问,而go get
在获取gocode
、go-def
、golint
等插件依赖工具的源码时,需要从 golang.org 上拉取部分代码至GOPATH
,自然就导致了最后这些依赖于 golang.org 代码的依赖工具安装失败。
GOPATH/src/
目录(不知道自己GOPATH
路径的,在终端输入go env
命令查看)创建
golang.org/x
目录。
#创建 golang.org/x 目录
mkdir -p golang.org/x
#进入新建目录内
cd golang.org/x
使用下列命令下载插件依赖工具的源码
➜ git clone https://github.com/golang/tools.git tools
Cloning into 'tools'...
remote: Enumerating objects: 62854, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 62854 (delta 3), reused 25 (delta 2), pack-reused 62827
Receiving objects: 100% (62854/62854), 28.92 MiB | 13.25 MiB/s, done.
Resolving deltas: 100% (45394/45394), done.
git clone
命令执行完毕后,所需的工具源码就都保存在tools目录中。
GOPATH
目录,根据之前的安装失败提示信息安装对应的依赖工具
go install -v github.com/ramya-rao-a/go-outline@latest
go install -v github.com/cweill/gotests/gotests@latest
go install -v github.com/fatih/gomodifytags@latest
go install -v github.com/josharian/impl@latest
go install -v github.com/haya14busa/goplay/cmd/goplay@latest
go install -v github.com/go-delve/delve/cmd/dlv@latest
go install -v honnef.co/go/tools/cmd/staticcheck@latest
go install -v golang.org/x/tools/gopls@latest
go install -v golang.org/x/tools/cmd/goimports@latest
插件安装完毕后重启 VS Code,插件就可以正常使用了。
go-tools安装包下载
提取码: ihu5
安装方法参考文件夹中的 README.md
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)