【Go】vs code安装 install/update tools 遇到zip: not a valid zip file

2023-12-15 14:03:49

在 vs code 安装 go 工具包 gopls 或 impl时遇到报错

Installing golang.org/x/tools/gopls@latest FAILED
{
 "code": 1,
 "killed": false,
 "signal": null,
 "cmd": "C:\\Program Files (x86)\\Go\\bin\\go.exe install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "go: downloading golang.org/x/tools/gopls v0.14.2\ngo: golang.org/x/tools/gopls@latest: zip: not a valid zip file\n"
}
Installing github.com/josharian/impl@v1.1.0 FAILED
{
 "code": 1,
 "killed": false,
 "signal": null,
 "cmd": "C:\\Program Files (x86)\\Go\\bin\\go.exe install -v github.com/josharian/impl@v1.1.0",
 "stdout": "",
 "stderr": "go: downloading golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375\nC:\\code\\go\\pkg\\mod\\github.com\\josharian\\impl@v1.1.0\\impl.go:20:2: zip: not a valid zip file\n"
}
gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: C:\Program Files (x86)\Go\bin\go.exe install -v golang.org/x/tools/gopls@latest
go: downloading golang.org/x/tools/gopls v0.14.2
go: golang.org/x/tools/gopls@latest: zip: not a valid zip file
 
impl: failed to install impl(github.com/josharian/impl@v1.1.0): Error: Command failed: C:\Program Files (x86)\Go\bin\go.exe install -v github.com/josharian/impl@v1.1.0
go: downloading golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375
C:\code\go\pkg\mod\github.com\josharian\impl@v1.1.0\impl.go:20:2: zip: not a valid zip file

尝试了一些方法都没有生效,包括使用 go clean -modcache命令。

最后通过切换代理源

go env -w GOPROXY=https://goproxy.cn,direct

从阿里代理源切换为 goproxy.cn,direct
再使用 go clean -modcache 命令
最后安装成功

在这里插入图片描述

文章来源:https://blog.csdn.net/yr12Dong/article/details/135013216
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。