首页 > 其他分享 >Go 疑难杂症汇总

Go 疑难杂症汇总

时间:2024-10-10 20:59:34浏览次数:1  
标签:github 疑难杂症 汇总 go lubanseven https gopkgs Go com

 

 

Go Modules 终极入门

https://eddycjy.com/posts/go/go-moduels/2020-02-28-go-modules/                  

 

 

 

https://www.cnblogs.com/xingzheanan/p/15700302.html

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/[email protected] requires
        github.com/uudashr/gopkgs/[email protected] requires
        github.com/uudashr/[email protected]: 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/[email protected] requires
        github.com/hashicorp/vault/api/auth/[email protected]: 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 [email protected]:.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/[email protected] requires
        github.com/hashicorp/vault/api/auth/[email protected]: 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 操作,连接。

参考

  1. 在解决问题过程中,参考了以下资料,效果不错适合参考:

 

 

asd

 

Go Modules 终极入门

标签:github,疑难杂症,汇总,go,lubanseven,https,gopkgs,Go,com
From: https://www.cnblogs.com/rebrobot/p/18457136

相关文章

  • 20AB-day3 Good Subsegments
    20AB-day3GoodSubsegments题意给你一个长度为\(n\)的序列\(a\),问有多少个子区间,满足\(\sum_{i=l}^r2^{a_i}=2^x\),其中\(x\)为非负整数。原题解第一个想法:若\(2^{a_l}+2^{a_{l+1}}+\cdots+2^{a_r}=2^x\),则\(x\le\max(a_l,a_{l+1},\cdots,a_r)+\logn\)。第二......
  • 28. 找出字符串中第一个匹配项的下标 Golang实现
    题目描述:给你两个字符串haystack和needle,请你在haystack字符串中找出needle字符串的第一个匹配项的下标(下标从0开始)。如果needle不是haystack的一部分,则返回-1。示例1:输入:haystack="sadbutsad",needle="sad"输出:0解释:"sad"在下标0和6处匹配。......
  • 全志用户层修改开机logo
    参考tina系统应用层更新开机logo_tinauboot加载bootlogo-CSDN博客 全志tina系统的开机logo显示方式有两种。分别是:是uboot中读取logo到内存中,然后kernel去显示/common/board_r.c init_sequence_r #ifdefCONFIGREADLOGOFORKERNEL sunxi_read_bootlogo, rb......
  • 10月最新AI产品经理面试20个问题汇总(含面试解题技巧、注意事项)
    这题我会!这是一个包含AI产品经理问题的备考文章,本文主要讲解AI产品经理的备考注意事项、真题展示、解题技巧及高效刷题方法,相信大家看完就一定能掌握技巧并且顺利通关!一、AI产品经理面试问题展示(20道)\1.请描述一下你过去负责的一个AI产品开发项目,包括项目的目标、过程......
  • GoldenEye-v1靶场
    通过netdiscover主机发现探测出靶场ip通过nmap扫描工具进行全端口扫描发现开了25,80,5006,5007这四个端口访问80端口百度翻译结果:Severnaya辅助控制站****绝密访问****访问服务器标识服务器名称:。。。。。。。。。。。。。。。。。。。。GOLDENEYE用户:未知导航......
  • ArgoWorkflow教程(六)---无缝实现步骤间参数传递
    之前我们分析了,Workflow、WorkflowTemplate、template3者之间如何传递参数。本文主要分析同一个Workflow中的不同step之间实现参数传递,比如将上一个步骤的输出作为下一个步骤的结果进行使用(而非以文件方式传递)。1.概述然后就是之前只分析了Workflow、WorkflowTemplat......
  • Pytorch常用代码段汇总
    来源:https://zhuanlan.zhihu.com/p/104019160PyTorch最好的资料是官方文档。本文是PyTorch常用代码段,在参考资料[1](张皓:PyTorchCookbook)的基础上做了一些修补,方便使用时查阅。1.基本配置导入包和版本查询importtorchimporttorch.nnasnnimporttorchvisionprint(to......
  • Django使用uwsgi和nginx进行手动部署
    在Django项目中使用uWSGI和Nginx进行部署是一种常见的生产环境配置。以下是一个详细的步骤指南,帮助你完成这个过程。前提条件有一个已经开发好的Django项目。服务器已安装Python、pip、Nginx和uWSGI。有一个有效的域名(可选,但推荐)。步骤一:准备Django项目收集静态文件:在项......
  • 游戏中脚本方式值修改-Godot Engine
    游戏为Tower.Tactics.Liberation游戏使用引擎GodotEngine,版本3.5.2游戏中的数值全是脚本中修改,内部名称为GDScript游戏运行中脚本的主函数为GDScriptFunction__call,脚本运行时的ip值只有在栈上储存,需要在函数中间Hook,获取到脚本的ip,顺便一起获取codeptrAsmHook......
  • Django替换sqlite默认数据库到mysql的一系列操作
    将这部分注释掉:DATABASES={'default':{'ENGINE':'django.db.backends.sqlite3','NAME':BASE_DIR/'db.sqlite3',}} 并替换为:DATABASES={'default':{......