聊聊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 结构型设计模式 桥接模式

Go从学会到学废】(零) Golang简介

分布式事务最经典的七种解决方案

聊聊promtail的client

手撸Golang 架构设计原则 合成复用原则

Golang中将字节流转为protobuf

Go session

使用 Go 1.16 的 signal.notifycontext 让你的服务重启更优雅

Golang如何判断channel已经close

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




打赏

取消

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

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

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

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

评论

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