聊聊golang的DDD项目结构


本文摘自网络,作者,侵删。

本文主要研究一下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 语言学习之初步认识

手撸Golang 行为型设计模式 策略模式

Golang make和new区别

Go + websocket 快速实现一个 chat 服务

Go:实现秒级读取16gb文件

Go stl 查询 db 引发的内存泄露

Go的切片(进阶版)

Golang一行代码把array/slice转成逗号分隔的字符串

Golang判断是文件还是文件夹

Golang 几种字符串的连接方式

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...