You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
1 month ago | |
|---|---|---|
| .. | ||
| cmd/server | 1 month ago | |
| configs | 1 month ago | |
| docs | 1 month ago | |
| internal | 1 month ago | |
| pkg/logger | 1 month ago | |
| README.md | 1 month ago | |
| go.mod | 1 month ago | |
| modify.md | 1 month ago | |
README.md
Aurora Golang Clean Architecture Template
这是一个基于 Go + Gin + GORM 的多数据库自动切换项目模板,遵循 Clean Architecture 分层思想。模板默认支持 SQLite、MySQL 与 PostgreSQL,使用配置文件即可切换数据库驱动。
结构说明
.
├── cmd/
│ └── server/ # 应用入口
├── configs/
│ └── config.yaml # 默认配置文件
├── internal/
│ ├── config/ # 配置加载
│ ├── domain/ # 领域模型和接口
│ ├── infrastructure/ # 数据库与仓储实现
│ ├── interface/ # HTTP 适配器
│ └── usecase/ # 应用服务
├── pkg/
│ └── logger/ # 日志封装
└── go.mod
快速开始
-
安装依赖
go mod tidy -
根据需要调整
configs/config.yaml或.env中的数据库驱动参数,可选值:sqlitemysqlpostgres/postgresql
-
运行服务
go run ./cmd/server -
示例接口
GET /api/v1/usersGET /api/v1/users/:idPOST /api/v1/users
数据库自动切换
通过配置文件中的 database.driver 自动选择对应的 GORM 驱动:
- SQLite 会在
data/aurora.db下生成数据库文件(路径可配置) - MySQL、PostgreSQL 根据配置生成 DSN,支持额外连接参数
清晰的分层设计
domain: 定义核心业务实体与仓储接口usecase: 聚合业务逻辑,依赖仓储接口infrastructure: 提供 GORM 仓储实现、数据库初始化等interface/http: 提供 Gin HTTP 适配器cmd/server: 组装依赖、启动服务
下一步
- 扩展更多领域模型与用例
- 集成依赖注入框架
- 增加测试与 CI/CD
欢迎在此模板基础上继续拓展,构建您的业务服务。