英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论