英文:
GO no go.mod file exists in directory
问题
我正在使用GO开始,并且想要创建一个类似Python中的虚拟环境(将导入的模块存储在项目目录本身),我在GO的文档https://go.dev/doc/tutorial/workspaces中阅读到,了解到GO的创建工作区是我需要做的。但是当我这样做时,它不起作用。就像附图中所示,在"go mod init .../hello_go"完成后,然后"go work init ./hello_go"出现了一些问题。
我不明白问题出在哪里?
英文:
I'm starting with GO, and I want to create a virtualenv like in Python (to store import modules at the project directory itself), I read in GO's doc https://go.dev/doc/tutorial/workspaces and understand that GO's Create the workspace is what i'm doing need. But when I do, it doesn't work. Like in the attached image, after "go mod init .../hello_go" complete, then "go work init ./hello_go" and something wrong.
I don't understand what is the problem?
答案1
得分: 0
问题在于go.work
文件应该位于项目的根目录,并指向包含go.mod
文件的子目录。
错误提示告诉你,没有./hello_go目录包含一个go.mod
文件。这是正确的,因为你已经在根级别初始化了你的模块。
如果你只有一个模块,你不需要创建一个工作区。你可以像你所做的那样在根级别创建你的模块,然后使用go mod
来管理该特定模块的依赖关系。
英文:
The problem is that the go.work
file is supposed to be at the root of your project and point to subdirectories containing a go.mod
file.
The error is telling you that there is no directory ./hello_go containing a go.mod
file. This is correct because you have initialized your module also at the root level.
If you have only a single module, you don't need to create a workspace. You can create your module at root level like you did, and then use go mod
to manage your dependencies for that particular module.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论