在使用 go mod 管理项目结构时,将 app.go 文件放置在 src 目录下是不可取的。建议遵循以下结构: app ├── go.mod ├── makefile ├── httpd | └── main.go └── platform └── user └── user.go
我在我的项目中使用以下结构,但感觉很hacky
app
├── go.mod
├── app.go
└── src
└── foo
| └── foo.go
└── bar
└── bar.go
有没有办法这样组织它?
App
├── go.mod
└── src
├── app.go
└── foo
| └── foo.go
└── bar
└── bar.go解决方案
您可以将 app.go 文件移动到 src 目录中。
但是,在 go 项目中拥有 src 文件夹通常是不明智的。我建议你看看 here 的建议:项目结构。
我喜欢下面的结构
app ├── makefile ├── go.mod ├── httpd <- entrypoint is here - cli or http server | └── main.go └── platform <- project specific dependencies that are not shared between projects
例如
App
├── makefile
├── go.mod
├── httpd
| └── handlers
| | └── hello-world_get.go
| | └── hello-world_get_test.go
| └── main.go
└── platform
└── user
└── user.go
└── user_test.go
我在 youtube 上描述了它 https://youtu.be/zeme_TmXyBk
好了,本文到此结束,带大家了解了《go mod子目录结构》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
本文内容来源于互联网,如有侵权请联系删除。
