go mod tidy “all” matched no packages

huangapple go评论126阅读模式
英文:

go mod tidy "all" matched no packages

问题

我已经创建了一个使用以下代码的Go模块:

go mod init rtws
vim main.go # 从示例中粘贴了一大段代码
go mod tidy

这两个文件都导入了"github.com/gorilla/websocket",所以当我使用tidy命令时,我期望它会下载该依赖项,但实际上我得到了以下警告:

go: warning: "all" matched no packages

随后尝试运行它时,它报告该依赖项不存在。
这个错误是什么意思?

编辑:在搜索时,我找到了最相关的内容是Stack Overflow上的另一个问题。很多人在运行其他命令时都遇到了这个警告,但他们的解决方案对于这个特定的情况没有起作用。

英文:

I've created a go module using this:

go mod init rtws
vim main.go # pasted a bunch of code from an example
go mod tidy

Both of these files import "github.com/gorilla/websocket", so when I used tidy I expected that it would download that dependency, but instead I got the following warning:

go: warning: "all" matched no packages

And subsequently trying to run it complained that the dependency did not exist.
What does this error mean?

EDIT: when searching, the most relevant thing I found was this other question on SO. A lot of people had this warning come up when running other commands but their solutions didn't work for this particular situation.

答案1

得分: 2

我发现了在我写问题的过程中导致问题的原因。在我粘贴的代码的顶部有以下几行:

//go:build ignore
// +build ignore

所以,显然这个警告意味着模块中没有文件。上述代码告诉Go的构建系统忽略该文件,因此go mod tidy的行为就像该文件不存在一样。

删除这些代码后,go mod tidy就能按照我最初的期望进行操作了。作为对Go语言不太熟悉的新手,这个特性并不是我考虑的首要事项。

英文:

I've found out what caused the issue while I was writing the question. At the top of the code that I pasted were the following lines:

//go:build ignore
// +build ignore

So, apparently this warning means there were no files in the module. The effect of the above lines tells go's build system to ignore that file, so go mod tidy behaved in the same way it would have if that file didn't exist.

Removing these allowed go mod tidy to do what I originally expected it to. Being new to golang this feature was not on the top of things I would have considered.

huangapple
  • 本文由 发表于 2022年6月4日 00:14:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/72492422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定