feat(core): implement group-based routing and optimize sync

Replace direct provider linkage with group-based routing for Keys and
Providers. This allows for more flexible load balancing and tiering
strategies.

Changes include:
- Remove `ProviderID` from Key model and DTO
- Add `Group` field to Key and Provider models
- Refactor Redis sync to use Hashes for O(1) partial updates
- Update API handlers to perform incremental syncs

BREAKING CHANGE: Key API payload no longer accepts `provider_id`. Redis
configuration storage format has changed from JSON strings to Hashes.
This commit is contained in:
zenfun
2025-12-02 14:41:05 +08:00
parent 57d92de5e6
commit aa57af874c
5 changed files with 154 additions and 93 deletions

View File

@@ -17,16 +17,16 @@ type Provider struct {
Type string `gorm:"not null" json:"type"` // openai, anthropic, etc.
BaseURL string `json:"base_url"`
APIKey string `json:"api_key"`
Group string `gorm:"default:'default'" json:"group"` // routing group/tier
}
type Key struct {
gorm.Model
ProviderID *uint `json:"provider_id"`
Provider *Provider `json:"-"`
KeySecret string `gorm:"not null" json:"key_secret"`
Balance float64 `json:"balance"`
Status string `gorm:"default:'active'" json:"status"` // active, suspended
Weight int `gorm:"default:10" json:"weight"`
KeySecret string `gorm:"not null" json:"key_secret"`
Group string `gorm:"default:'default'" json:"group"` // routing group/tier
Balance float64 `json:"balance"`
Status string `gorm:"default:'active'" json:"status"` // active, suspended
Weight int `gorm:"default:10" json:"weight"`
}
type Model struct {