前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >聊聊golang的DDD项目结构

聊聊golang的DDD项目结构

原创
作者头像
code4it
修改2021-03-12 10:44:32
1.4K0
修改2021-03-12 10:44:32
举报
文章被收录于专栏:码匠的流水账

本文主要研究一下golang的DDD项目结构

interfaces

food-app-server/interfaces

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • interfaces
  • application
  • domain
  • infrastructure
  • 小结
  • doc
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档