英文:
Go folder structure same package
问题
让我们假设我想按照以下方式对项目文件进行排序:
- src
- myProject
- main.go
- models
- foo.go
- bar.go
我该如何告诉编译器这个结构?目前看起来,所有的文件都必须放在myProject
文件夹中,尽管有很多模型,这样很快就会变得拥挤。
有没有一种方法可以在不使用外部包的情况下实现这种结构?(即我仍然希望在models/foo
中使用主包)
英文:
Let's say I want to order my project files like this:
- src
- myProject
- main.go
- models
- foo.go
- bar.go
How can I tell the compiler about this structure, at the moment it looks that all my files have to be in the myProject
folder, although with quite a few models, this will get crowded really quickly.
Is there a way I can achieve this structure without having to use external packages? (i.e. I still want to use the main package inside models/foo
)
答案1
得分: 5
go工具假设每个包对应一个目录。
你可以直接运行编译器和链接器来实现任何你想要的布局。因为没有人这样做,所以你会发现支持这种方法的文档很少。
随波逐流。使用多个包。
英文:
The go tool assumes one directory per package.
You can run the compiler and linker directly to achieve any layout you want. Because nobody does this, you will find that documentation to support this approach is slim.
Go with the flow. Use more than one package.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论