feat: key接口完善及错误处理

This commit is contained in:
tbphp
2025-07-05 14:50:58 +08:00
parent 8d7b60875e
commit d64ada4181
12 changed files with 487 additions and 208 deletions

View File

@@ -52,11 +52,12 @@ type Group struct {
// APIKey 对应 api_keys 表
type APIKey struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
GroupID uint `gorm:"not null" json:"group_id"`
KeyValue string `gorm:"type:varchar(512);not null" json:"key_value"`
KeyValue string `gorm:"type:varchar(512);not null;uniqueIndex:idx_group_key" json:"key_value"`
GroupID uint `gorm:"not null;uniqueIndex:idx_group_key" json:"group_id"`
Status string `gorm:"type:varchar(50);not null;default:'active'" json:"status"`
RequestCount int64 `gorm:"not null;default:0" json:"request_count"`
FailureCount int64 `gorm:"not null;default:0" json:"failure_count"`
ErrorReason string `gorm:"type:text" json:"error_reason"`
LastUsedAt *time.Time `json:"last_used_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`