Files
ez-api/internal/model/models.go
zenfun 64d71953a6 feat(server): implement management endpoints and redis sync
Enable full resource management via API and support data plane
synchronization.

- Add CRUD handlers for Providers, Models, and Keys using DTOs
- Implement LogWriter service for asynchronous, batched audit logging
- Update SyncService to snapshot full configuration state to Redis
- Register new API routes and initialize background services
- Add configuration options for logging performance tuning
2025-12-02 14:26:16 +08:00

43 lines
1.3 KiB
Go

package model
import (
"gorm.io/gorm"
)
type User struct {
gorm.Model
Username string `gorm:"uniqueIndex;not null" json:"username"`
Quota int64 `gorm:"default:0" json:"quota"`
Role string `gorm:"default:'user'" json:"role"` // admin, user
}
type Provider struct {
gorm.Model
Name string `gorm:"not null" json:"name"`
Type string `gorm:"not null" json:"type"` // openai, anthropic, etc.
BaseURL string `json:"base_url"`
APIKey string `json:"api_key"`
}
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"`
}
type Model struct {
gorm.Model
Name string `gorm:"uniqueIndex;not null" json:"name"`
ContextWindow int `json:"context_window"`
CostPerToken float64 `json:"cost_per_token"`
SupportsVision bool `json:"supports_vision"`
SupportsFunctions bool `json:"supports_functions"`
SupportsToolChoice bool `json:"supports_tool_choice"`
SupportsFIM bool `json:"supports_fim"`
MaxOutputTokens int `json:"max_output_tokens"`
}