DDD & onion architecture sample in Go.
core— 数据模型(实体)domain— 仓储接口与实现(端口/适配器中的端口)handlers— 应用层用例(业务编排)infrastructure— 组合根(Composition Root),负责依赖注入与启动
依赖方向:handlers → domain → core,infrastructure 组装各层,main 仅引导启动。
go run .
# 或
make build && ./bin/ddd-onion-sample本项目使用显式构造函数注入,不再依赖反射或 ClassLoader:
repo := domain.NewUserMockRepo()
handler, _ := handlers.NewUserHandler(repo)
app, _ := infrastructure.NewApp(infrastructure.Config{})替换 UserRepository 实现(如真实 DB)只需在 NewApp 中切换构造逻辑。
- 增加标准文件说明:日志,配置等
- 加入到 gorut 项目中,形成模板
- HTTP 服务器接入