关于golang:聊聊golang的DDD项目结构

9次阅读

共计 1420 个字符,预计需要花费 4 分钟才能阅读完成。

本文次要钻研一下 golang 的 DDD 我的项目构造

interfaces

food-app-server/interfaces

interfaces git:(master) tree
.
|____fileupload
| |____fileformat.go
| |____fileupload.go
|____food_handler.go
|____food_handler_test.go
|____handler_setup_test.go
|____login_handler.go
|____login_handler_test.go
|____middleware
| |____middleware.go
|____user_handler.go
|____user_handler_test.go

比方 interfaces 层定义了输出层的相干办法,以应用 gin 提供 http 接口为例,这里的 handler 等为应用 gin 提供的一些 http 接口,这一层调用 application 层

application

food-app-server/application

application git:(master) tree
.
|____food_app.go
|____food_app_test.go
|____user_app.go
|____user_app_test.go

application 层次要是调用 domain 层与 infrastructure 层来实现性能

domain

food-app-server/domain

domain git:(master) tree
.
|____entity
| |____food.go
| |____user.go
|____repository
| |____food_repository.go
| |____user_repository.go

domain 层次要是定义了 entity,以及 repository 接口;entity 外头会蕴含一些畛域逻辑

infrastructure

food-app-server/infrastructure

infrastructure git:(master) tree
.
|____auth
| |____auth.go
| |____redisdb.go
| |____token.go
|____persistence
| |____db.go
| |____food_repository.go
| |____food_repository_test.go
| |____setup_test.go
| |____user_repository.go
| |____user_repository_test.go
|____security
| |____password.go

infrastructure 层这里提供了针对 domain 层的 repository 接口的实现,还有其余一些根底的组件,提供给 application 层或者 interfaces 层应用

小结

DDD 个别分为 interfaces、application、domain、infrastructure 这几层;其中 domain 层不依赖其余层,它定义 repository 接口,infrastructure 层会实现;application 层会调用 domain、infrastructure 层;interfaces 层个别调用 application 层或者 infrastructure 层。

doc

  • food-app-server
正文完
 0