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.
 
 
 
 
root 87905c84a9 add ssh plink 1 month ago
..
cmd/server add ssh plink 1 month ago
configs add ssh plink 1 month ago
docs add ssh plink 1 month ago
internal add ssh plink 1 month ago
pkg/logger add ssh plink 1 month ago
README.md add ssh plink 1 month ago
go.mod add ssh plink 1 month ago
modify.md add ssh plink 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

快速开始

  1. 安装依赖

    go mod tidy
    
  2. 根据需要调整 configs/config.yaml.env 中的数据库驱动参数,可选值:

    • sqlite
    • mysql
    • postgres / postgresql
  3. 运行服务

    go run ./cmd/server
    
  4. 示例接口

    • GET /api/v1/users
    • GET /api/v1/users/:id
    • POST /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

欢迎在此模板基础上继续拓展,构建您的业务服务。