zoukankan      html  css  js  c++  java
  • Go 疑难杂症汇总


    1. revision v0.0.0: unknown revision v0.0.0

    go get -u github.com/uudashr/gopkgs/cmd/gopkgs 报错:

    [root@lubanseven home]$ go get -u github.com/uudashr/gopkgs/cmd/gopkgs
    go: downloading github.com/uudashr/gopkgs v1.3.2
    go: downloading github.com/uudashr/gopkgs/cmd/gopkgs v0.0.0-20191024034442-58e9141cd7d6
    go: downloading github.com/uudashr/gopkgs v2.0.1+incompatible
    go: github.com/uudashr/gopkgs/cmd/gopkgs upgrade => v0.0.0-20191024034442-58e9141cd7d6
    go get: github.com/uudashr/gopkgs/cmd/gopkgs@v0.0.0-20191024034442-58e9141cd7d6 requires
            github.com/uudashr/gopkgs/v2@v2.1.0 requires
            github.com/uudashr/gopkgs@v0.0.0: reading github.com/uudashr/gopkgs/go.mod at revision v0.0.0: unknown revision v0.0.0
    

    根据 Cannot install gopkgs tool,换个 gopkgs 安装:

    [root@lubanseven delve]$ go get github.com/uudashr/gopkgs/v2/cmd/gopkgs
    go: downloading github.com/uudashr/gopkgs/v2 v2.1.2
    go: found github.com/uudashr/gopkgs/v2/cmd/gopkgs in github.com/uudashr/gopkgs/v2 v2.1.2
    go: downloading github.com/karrick/godirwalk v1.12.0
    go: downloading github.com/pkg/errors v0.8.1
    

    2. invalid version: unknown revision

    2.1 现象及解决方法

    go run cmd/main.go 时报错:

    [root@lubanseven go]# go run svc/lubanseven/cmd/lubanseven/main.go
    vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/metrics.go:21:2: cannot find package "." in:
            /home/lubanseven/go/src/AANM/go/vendor/io/fs
    

    查看项目 go.mod 文件发现文件定义版本(1.16) 和当前 go version 版本(1.15.15) 不一致。于是删掉 go.mod 文件,重新 go mod init <project_name>,执行 go mod tidy 报错:

    go: github.com/hashicorp/vault@v1.9.1 requires
            github.com/hashicorp/vault/api/auth/approle@v0.0.0-00010101000000-000000000000: invalid version: unknown revision 000000000000
    

    查阅文档发现 go mod tidy 调用的是 go get,接着调用的是 git 下载 github 的包。于是使用 go get 命令手动下载 vault:

    go get -u github.com/hashicorp/vault
    

    报错:

    ssh:connect to host github.com port 22: Connection timed out.
    

    ssh 连接的报错,有可能 port 端口不是 22,也有可能是别的原因,这里并未深究,将下载方式从 ssh 切换到 https:

    git config --global url.git@github.com:.insteadOf https://github.com/
    

    接着执行 go get 手动下载 go: github.com/hashicorp/vault 继续报错:

    Permission denied (publickey).
    fatal: Could not read from remote repository.
    

    提示 Permission denied,将 public key 添加到 github 上,继续执行 go get -u,继续报错:

    go: github.com/hashicorp/vault@v1.9.1 requires
            github.com/hashicorp/vault/api/auth/approle@v0.0.0-00010101000000-000000000000: invalid version: unknown revision 000000000000
    

    看来路走错了,接着搜文档,发现和之前把 go.mod 删掉有关系。之前的 go.mod 中有 replace 字段定义包版本的行为,现在新建的包并没有 replace,也没有 require。

    将之前包版本的 require 复制到当前 go.mod(只复制了 require 并未复制 replace),接着执行 go mod tidy,下载完成。

    3. cannot find package "." in:*******

    执行 go run cmd/main.go 报错:

    [root@lubanseven go]# go run svc/lubanseven/cmd/lubanseven/main.go
    vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/metrics.go:21:2: cannot find package "." in:
            /home/lubanseven/go/src/AANM/go/vendor/io/fs
    

    还是原来那个错...

    查阅文档发现 GOPATH 包路径不对,当前执行路径是:

    [root@lubanseven go]# pwd
    /home/lubanseven/vsWorkspace/dev/go
    
    // GOPATH 路径
    [root@lubanseven ~]# go env | grep -i path
    GOPATH="/root/go"
    

    于是按照文档要求将代码复制到 GOPATH 路径下,挫是挫了点,但是此刻能运行已经什么都不在乎了。接着执行,还是报一样的错...

    冷静思考一番,还是从开始的 go.mod 入手,开始的 go.mod 定义了 go 版本是 1.16 这里我们换了版本出现了这一系列问题,会不会是 go 版本的问题呢?于是,将 go 版本从 1.15 换到 1.16,接着执行 go run cmd/main.go 执行成功...

    4. fatal: unable to find remote helper for 'https'

    go mod tidy 报错:

    [root@lubanseven home]$ go mod tidy
    Gin imports
            github.com/gin-gonic/gin: git ls-remote -q origin in /root/go/pkg/mod/cache/vcs/a923aa3ae357f66c754ef34c3358c689f5d969293b012aef737373496ea3e                   ef3: exit status 128:
            fatal: unable to find remote helper for 'https'
    

    根据 unable-to-find-remote-helper-for-https-during-git-clone 设置:

    $ yum install curl-devel
    $ # cd to wherever the source for git is
    $ cd /usr/local/src/git-1.7.9  
    $ ./configure
    $ make
    $ make install
    

    由于没找到 git configure 目录,直接 yum remove git,然后 yum install git。接着执行 go mod tidy 报错:

    go: finding module for package github.com/gin-gonic/gin
    Gin imports
            github.com/gin-gonic/gin: module github.com/gin-gonic/gin: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/list": proxyconnect tcp:                    EOF
    

    看报错信息和代理有关系,重新配置代理,执行 go mod tidy 成功安装 Gin。

    5. Get "https://xxx": unexpected EOF

    go get -v github.com/rogpeppe/godef 报错:

    go get github.com/rogpeppe/godef: module github.com/rogpeppe/godef: Get "https://goproxy.cn/github.com/rogpeppe/godef/@v/list": unexpected EOF
    

    根据 go get not working with unexpected EOF 取消 https_proxy,重新 go get,成功!

    注意:也要留意 http_proxy 的情况,配置 http_proxy 也会遇到此类问题。

    6. fatal: unable to access xxx Encountered end of file

    git clone https://github.com/go-delve/delve 通过 clone 的方式安装 delve,报错:

    [root@lubanseven home]$ git clone https://github.com/go-delve/delve
    Cloning into 'delve'...
    fatal: unable to find remote helper for 'https'
    

    出现了问题 4 一样的报错,但前面已经配置过了为什么还会报错呢?和前面的处理应该没关系。怀疑归怀疑,按照问题 4 的解决方式重新走一遍,报同样的错。

    根据 Unable to find remote helper for https 设置 PATH 环境变量:

    [root@lubanseven home]$ PATH=$PATH:/usr/libexec/git-core
    [root@lubanseven home]$ git clone https://github.com/go-delve/delve
    Cloning into 'delve'...
    fatal: unable to access 'https://github.com/go-delve/delve/': Encountered end of file
    

    现在报 Encountered end of file 错误,根据 fatal: unable to access xxx Encountered end of file 设置 git config:

    [root@lubanseven home]$ git config --global http.proxy
    [root@lubanseven home]$ git config --global --unset http.proxy
    [root@lubanseven home]$ git clone https://github.com/go-delve/delve
    Cloning into 'delve'...
    warning: You appear to have cloned an empty repository.
    

    重新 clone 成功。

    芝兰生于空谷,不以无人而不芳。
  • 相关阅读:
    每个zone的low memory是怎么计算出来的
    /proc/meminfo中meminfo的计算方法
    shmem:
    tc:逼良为娼
    内核抢占
    html/css/javascript知识点集锦;完全小白开搞web编程
    netem设置了网卡的流量控制,为啥发包的延迟就搞不定呢?
    滑动窗口
    发送缓冲区sk_wmem_queued
    ASP.NET MVC 实现区域 项目分离 (比较好的方式)
  • 原文地址:https://www.cnblogs.com/xingzheanan/p/15700302.html
Copyright © 2011-2022 走看看