79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package models
|
||
|
||
import "time"
|
||
|
||
// ========= ViewModel / DTOs for Dashboard API =========
|
||
type StatCard struct {
|
||
Value float64 `json:"value"`
|
||
SubValue any `json:"sub_value,omitempty"`
|
||
SubValueTip string `json:"sub_value_tip,omitempty"`
|
||
Trend float64 `json:"trend"`
|
||
TrendIsGrowth bool `json:"trend_is_growth"`
|
||
}
|
||
type DashboardStatsResponse struct {
|
||
KeyCount StatCard `json:"key_count"`
|
||
RPM StatCard `json:"rpm"`
|
||
RequestCount24h StatCard `json:"request_count_24h"`
|
||
ErrorRate24h StatCard `json:"error_rate_24h"`
|
||
KeyStatusCount map[APIKeyStatus]int64 `json:"key_status_count"`
|
||
MasterStatusCount map[MasterAPIKeyStatus]int64 `json:"master_status_count"`
|
||
TokenCount map[string]any `json:"token_count"`
|
||
UpstreamHealthStatus map[string]string `json:"upstream_health_status,omitempty"`
|
||
RequestCounts map[string]int64 `json:"request_counts"`
|
||
}
|
||
type ChartDataset struct {
|
||
Label string `json:"label"`
|
||
Data []int64 `json:"data"`
|
||
Color string `json:"color"`
|
||
}
|
||
type ChartData struct {
|
||
Labels []string `json:"labels"`
|
||
Datasets []ChartDataset `json:"datasets"`
|
||
}
|
||
|
||
// TokenUpdateRequest DTO for binding the PUT /admin/tokens request
|
||
type TokenUpdateRequest struct {
|
||
ID uint `json:"ID"`
|
||
Token string `json:"Token"`
|
||
Description string `json:"Description"`
|
||
Tag string `json:"Tag"`
|
||
Status string `json:"Status"`
|
||
IsAdmin bool `json:"IsAdmin"`
|
||
AllowedGroupIDs []uint `json:"AllowedGroupIDs"`
|
||
}
|
||
|
||
// 数据传输对象(DTO),表示单个Key的测试结果。
|
||
// ===================================================================
|
||
type KeyTestResult struct {
|
||
Key string `json:"key"`
|
||
Status string `json:"status"` // "valid", "invalid", "error"
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// APIKeyQueryParams defines the parameters for listing/searching keys.
|
||
type APIKeyQueryParams struct {
|
||
KeyGroupID uint `form:"-"`
|
||
Page int `form:"page"`
|
||
PageSize int `form:"limit"`
|
||
Status string `form:"status"`
|
||
Keyword string `form:"keyword"`
|
||
}
|
||
|
||
// APIKeyDetails is a DTO that combines APIKey info with its contextual status from the mapping.
|
||
type APIKeyDetails struct {
|
||
// Embedded APIKey fields
|
||
ID uint `json:"id"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
APIKey string `json:"api_key"`
|
||
MasterStatus MasterAPIKeyStatus `json:"master_status"`
|
||
|
||
// Mapping-specific fields
|
||
Status APIKeyStatus `json:"status"`
|
||
LastError string `json:"last_error"`
|
||
ConsecutiveErrorCount int `json:"consecutive_error_count"`
|
||
LastUsedAt *time.Time `json:"last_used_at"`
|
||
CooldownUntil *time.Time `json:"cooldown_until"`
|
||
EncryptedKey string
|
||
}
|