VIM 中执行 GoInstallBinaries 安装依赖失败

更新日期: 2022-04-11 阅读次数: 9284 字数: 363 分类: Vim

在 VIM 中安装了 vim-go 插件,但是在为其安装依赖时,执行

:GoInstallBinaries

失败,报错信息:

vim-go: errcheck not found. Installing github.com/kisielk/errcheck to folder /home/zhongwei/go/bin/

Error downloading github.com/kisielk/errcheck: github.com/kisielk/errcheck (download)^@package golang.org/x/tools/go/analysis: unrecognized import path "golang.org/x/tools/go/analysis": https fetch: Get "https://golang.org/x/tools/go/analysis?go-get=1": dial tcp 216.239.37.1:443: connect: connection refused^@package golang.org/x/tools/go/packages: unrecognized import path "golang.org/x/tools/go/packages": https fetch: Get "https://golang.org/x/tools/go/packages?go-get=1": dial tcp 216.239.37.1:443: connect: connection refused

看起来都是在直连 github,由于国内不可描述的原因导致下载失败。

这里下载 golang 依赖包,并没有走我配置的七牛云 golang 国内镜像源

所以,最简单的做法就是,把下载失败的依赖包,再手动复制到终端下 go get 安装。

我整理了一下,需要安装的依赖包如下,可以写一个安装脚本,批量安装:

#!/bin/bash

set -e	# or use "set -o errexit" to quit on error.
set -x  # or use "set -o xtrace" to print the statement before you execute it.

go get github.com/nsf/gocode
go get github.com/bradfitz/goimports
go get golang.org/x/tools/cmd/guru
go get golang.org/x/tools/cmd/gorename
go get github.com/rogpeppe/godef
go get github.com/kisielk/errcheck
go get github.com/jstemmer/gotags
go get github.com/klauspost/asmfmt/cmd/asmfmt
go get github.com/fatih/motion
go get github.com/zmb3/gogetdoc
go get github.com/josharian/impl
go get github.com/golangci/golangci-lint/cmd/golangci-lint
go get github.com/fatih/gomodifytags
go get honnef.co/go/tools/cmd/keyify
go get golang.org/x/lint/golint

安装完成后,再进入 VIM 中,执行 GoInstallBinaries 就可以成功了。

'go get' is no longer supported outside a module

升级 go 1.18 版本之后,这样搞就行不通了

go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

修改脚本如下:

#!/bin/bash

set -e	# or use "set -o errexit" to quit on error.
set -x  # or use "set -o xtrace" to print the statement before you execute it.

go install github.com/nsf/gocode@latest
go install github.com/bradfitz/goimports@latest
go install golang.org/x/tools/cmd/guru@latest
go install golang.org/x/tools/cmd/gorename@latest
go install github.com/rogpeppe/godef@latest
go install github.com/kisielk/errcheck@latest
go install github.com/jstemmer/gotags@latest
go install github.com/klauspost/asmfmt/cmd/asmfmt@latest
go install github.com/fatih/motion@latest
go install github.com/zmb3/gogetdoc@latest
go install github.com/josharian/impl@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/fatih/gomodifytags@latest
go install honnef.co/go/tools/cmd/keyify@latest
go install golang.org/x/lint/golint@latest
go install github.com/davidrjenni/reftools/cmd/fillstruct@master
go install github.com/go-delve/delve/cmd/dlv@master
go install github.com/koron/iferr@master

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式

谈笑风生

wofanli

可以直接改一下vim-go里的脚本,把go get改成go install

Atank

感谢大佬的脚本 🙏 虽然使用脚本还是无法更新,但是加上 sudo proxychains 就正常更新了