refactor: 重构后端架构为 go-zero 框架,优化项目结构

主要变更:
- 采用 go-zero 框架替代 Gin,提升开发效率
- 重构项目结构,API 文件模块化组织
- 将 model 移至 api/internal/model 目录
- 移除 common 包,改为标准 pkg 目录结构
- 实现统一的仓储模式,支持配置驱动数据库切换
- 简化测试策略,专注 API 集成测试
- 更新 CLAUDE.md 文档,提供详细的开发指导

技术栈更新:
- 框架: Gin → go-zero v1.6.0+
- 代码生成: 引入 goctl 工具
- 架构模式: 四层架构 → go-zero 三层架构 (Handler→Logic→Model)
- 项目布局: 遵循 Go 社区标准和 go-zero 最佳实践
This commit is contained in:
xujiang
2025-07-10 15:05:52 +08:00
parent a2f2f66f88
commit 39a42695d3
52 changed files with 6047 additions and 2349 deletions

View File

@ -6,7 +6,7 @@ import (
"gorm.io/gorm"
"gorm.io/driver/postgres"
"photography-backend/internal/config"
"photography-backend/internal/models"
"photography-backend/internal/model/entity"
)
// Database 数据库连接
@ -52,10 +52,10 @@ func NewDatabase(cfg *config.DatabaseConfig) (*Database, error) {
// AutoMigrate 自动迁移数据库表结构
func (d *Database) AutoMigrate() error {
return d.DB.AutoMigrate(
&models.User{},
&models.Category{},
&models.Tag{},
&models.Photo{},
&entity.User{},
&entity.Category{},
&entity.Tag{},
&entity.Photo{},
)
}