1
0

feat: 实现分层架构,包含 domain、service、repository 和 pkg 层

- 新增 domain 层:model、provider、route、stats 实体
- 新增 service 层:models、providers、routing、stats 业务逻辑
- 新增 repository 层:models、providers、stats 数据访问
- 新增 pkg 工具包:errors、logger、validator
- 新增中间件:CORS、logging、recovery、request ID
- 新增数据库迁移:初始 schema 和索引
- 新增单元测试和集成测试
- 新增规范文档:config-management、database-migration、error-handling、layered-architecture、middleware-system、request-validation、structured-logging、test-coverage
- 移除 config 子包和 model_router(已迁移至分层架构)
This commit is contained in:
2026-04-16 00:47:20 +08:00
parent 915b004924
commit f18904af1e
77 changed files with 5727 additions and 1257 deletions

View File

@@ -0,0 +1,12 @@
package domain
import "time"
// Model 模型领域模型
type Model struct {
ID string `json:"id"`
ProviderID string `json:"provider_id"`
ModelName string `json:"model_name"`
Enabled bool `json:"enabled"`
CreatedAt time.Time `json:"created_at"`
}

View File

@@ -0,0 +1,23 @@
package domain
import "time"
// Provider 供应商领域模型
type Provider struct {
ID string `json:"id"`
Name string `json:"name"`
APIKey string `json:"api_key"`
BaseURL string `json:"base_url"`
Enabled bool `json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// MaskAPIKey 掩码 API Key仅显示最后 4 个字符)
func (p *Provider) MaskAPIKey() {
if len(p.APIKey) > 4 {
p.APIKey = "***" + p.APIKey[len(p.APIKey)-4:]
} else {
p.APIKey = "***"
}
}

View File

@@ -0,0 +1,7 @@
package domain
// RouteResult 路由结果
type RouteResult struct {
Provider *Provider
Model *Model
}

View File

@@ -0,0 +1,12 @@
package domain
import "time"
// UsageStats 用量统计领域模型
type UsageStats struct {
ID uint `json:"id"`
ProviderID string `json:"provider_id"`
ModelName string `json:"model_name"`
RequestCount int `json:"request_count"`
Date time.Time `json:"date"`
}