我在项目中使用以下结构,但感觉很笨拙
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 文件夹通常是不明智的。我建议您在这里查看有关项目结构的建议。
我喜欢以下结构
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