本文摘自网络,作者,侵删。
序
本文主要研究一下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
本文来自:51CTO博客
感谢作者:mob604756e3cc85
查看原文:聊聊golang的DDD项目结构
相关阅读 >>
用 Go + websocket 快速实现一个 chat 服务
Golang一行代码把array/slice转成逗号分隔的字符串
更多相关阅读请进入《Go》频道 >>
Go语言101
一个与时俱进的Go编程知识库。