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 成功。
7. package embed is not in GOROOT (/usr/local/go/src/embed)
编译项目代码报错:package embed is not in GOROOT (/usr/local/go/src/embed)
。发现 embed 是 golang1.6 的内置函数,当前 golang 版本为 1.4。
遂尝试升级 golang 版本,根据 升级 Golang 尝试实现多版本 golang 管理。在 $GOPATH/pkg/mod/golang.org/dl/
下找到对应
go 版本(如果没有的话需要先下载: go get golang.org/dl/go<version>
),编译 main.go 为对应版本号:
$ go build -o go1.16.4 main.go
执行 ./go1.16.4 download
下载 go 软件包:
$ ./go1.16.4 download
go1.16.4: download failed: Head "https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz": dial tcp 142.250.74.78:443: i/o timeout
遇到了 i/o timeout
问题,查看 go env proxy 是否正确设置:
$ go env | grep proxy -i
GONOPROXY=""
GOPROXY="https://goproxy.cn,direct"
$ go env | grep 111 -i
GO111MODULE="on"
正确配置,在看这里的 142.250.74.78
是什么地址呢?
通过 wget 直接下载 https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
看看:
$ wget https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
--2022-02-20 15:16:34-- https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 142.250.74.110, 2a00:1450:400f:802::200e
Connecting to dl.google.com (dl.google.com)|142.250.74.110|:443...
解析的是域名 dl.google.com
的 ip,众所周知的原因访问不了 google 的服务器。配置代理,继续 wget:
$ export https_proxy=https://10.144.xxx.xxx:8080
$ wget https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
--2022-02-20 15:30:07-- https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
Connecting to 10.144.xxx.xxx:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 129044044 (123M) [application/x-gzip]
Saving to: ‘go1.16.4.linux-amd64.tar.gz’
0% [ ] 120,225 36.0KB/s eta 68m 14s
可以访问并下载!
理论上这么走通之后,可以实现多版本 go 管理了。不过这里后续没有走这条路(主要想折腾下多版本 go...),而是将原来的 go 删掉,重新安装新版本 go。
新版本安装完后,执行 go run main.go
,程序成功运行。
8. Could not import Golang package
vscode 提示:Could not import Golang package
,原因是前面在升级过程中将 GOPATH 替换了,导致 vscode原有窗口加载的 mod 找不到了。
解决方法是重启 vscode,重新加载 workspace,GOPATH 找到,问题解决。
9. vs code remote connect
通过 vs code remote-ssh 远程连接 server。
添加 keypair 到本地。ssh-keygen -t rsa -m PEM -f wenhu.pem
生成 pem 格式密钥。
将以 RSA 开头的密钥拷到本地,并将 OPENSSL 的密码添加到 authorized_keys。
remote-ssh 远程连接成功。
还有种方式是将已经连接成功的 keypair 拷到 server 上,执行类似添加 authorized_keys 操作,连接。
参考
- 在解决问题过程中,参考了以下资料,效果不错适合参考:
- Why does "go get" use HTTPS when cloning a repository?
- Go Modules、Go Module Proxy 和 goproxy.cn
- proxy.golang.org: does not work in China
Go 疑难杂症汇总的更多相关文章
- 原创:LNMP架构部署个人博客网站 禁止转载复制
nginx编译安装步骤 ①. 检查软件安装的系统环境 cat /etc/redhat-release uname -r ②. 安装nginx的依赖包(pcre-devel openssl-devel) ...
- Nginx初步入门
1.Nginx介绍 官网:nginx.org Nginx ("engine x") 是一个开源的.支持高性能.高并发的WWW服务和代理服务软件. 它是由俄罗斯人IgorSysoev ...
- APM(pixhawk)飞控疑难杂症解决方法汇总(持续更新)
本文转自下面博主 https://blog.csdn.net/junzixing/article/details/79310159 APM/Pixhawk常用链接汇总(持续更新) https://bl ...
- TCP协议疑难杂症全景解析
说明: 1).本文以TCP的发展历程解析容易引起混淆,误会的方方面面2).本文不会贴大量的源码,大多数是以文字形式描述,我相信文字看起来是要比代码更轻松的3).针对对象:对TCP已经有了全面了解的人. ...
- 【转载】TCP协议疑难杂症全景解析
说明: 1).本文以TCP的发展历程解析容易引起混淆,误会的方方面面2).本文不会贴大量的源码,大多数是以文字形式描述,我相信文字看起来是要比代码更轻松的3).针对对象:对TCP已经有了全面了解的人. ...
- 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)
前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...
- 异常处理汇总 ~ 修正果带着你的Net飞奔吧!
经验库开源地址:https://github.com/dunitian/LoTDotNet 异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983 ...
- Carousel 旋转画廊特效的疑难杂症
疑难杂症 该画廊特效的特点就是前后元素有层级关系. 我想很多人应该看过或者用过这个插件carousel.js,网上也有相关的教程.不知道这个插件的原型是哪个,有知道的朋友可以告诉我. 该插件相对完美, ...
- UWP开发必备:常用数据列表控件汇总比较
今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...
- Oracle手边常用70则脚本知识汇总
Oracle手边常用70则脚本知识汇总 作者:白宁超 时间:2016年3月4日13:58:36 摘要: 日常使用oracle数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规 ...
随机推荐
- C++学习笔记四:变量与数据类型(布尔型与字符型)
今天来整理一下布尔型和字符型变量的基本使用方法1)布尔型变量1. 声明和初始化一个布尔类型的变量占据1 Byte空间,数值0代表false,其他非0数值代表true bool red_light {f ...
- OkHttp3发送http请求
导入依赖 <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> <dependency> ...
- LeetCode331:验证二叉树的前序序列化(递归)
解题思路:把所有元素存成数组,设置一个全局下标next,表示当前节点如果要继续遍历应当从数组的哪个位置开始,然后从下标 0 开始DFS.如果DFS返回真并且next下标等于数组的长度,说明元素已经全部 ...
- Draco使用笔记(1)——图形解压缩
目录 1. 概述 2. 详论 2.1. 工具 2.2. 代码 1. 概述 Draco是Google开发的图形压缩库,用于压缩和解压缩3D几何网格(geometric mesh)和点云(point cl ...
- 华为亮相KubeCon EU 2023 新云原生开源项目Kuasar推动“云上演进”
摘要:协力同行.拥抱开源,解放数字生产力,为社会和行业带来更多价值. 在数字时代,如果说企业是一艘巨大的货船,那么云原生则为企业的每一个业务.每一个应用提供了标准化的集装箱,摆脱笨重的底层桎梏,打造新 ...
- Volcano 监控设计解读,一看就懂
摘要:Volcano 方便AI,大数据,基因,渲染等诸多行业通用计算框架介入,提供高性能任务调度引擎,高性能异构芯片管理,高性能任务运行管理等能力. Volcano 是一个 Kubernetes 云原 ...
- 华为云数据库GaussDB(for openGauss):初次见面,认识一下
摘要:本文从总体架构.主打场景.关键技术特性等方面进行介绍GaussDB(for openGauss). 1.背景介绍 3月16日,在华为云主办的GaussDB(for openGauss)系列技术第 ...
- 跟我学ModelArts丨探索ModelArts平台个性化联邦学习API
摘要:ModelArts提供了一个实现个性化联邦学习的API--pytorch_fedamp_emnist_classification,它主要是让拥有相似数据分布的客户进行更多合作的一个横向联邦学习 ...
- 面向对象的Python编程,你需要知道这些!
摘要:Python 没有像 java 中的"private"这样的访问说明符.除了强封装外,它支持大多数与"面向对象"编程语言相关的术语.因此它不是完全面向对象 ...
- Linux IPTables:如何添加防火墙规则
摘要:本文介绍了如何使用"iptables -A"命令添加 iptables 防火墙规则. 本文分享自华为云社区<Linux IPTables:如何添加防火墙规则(使用允许 ...