Refactor configuration and key management

- Removed key management configuration from .env.example and related code.
- Updated Makefile to load environment variables for HOST and PORT.
- Modified main.go to handle request logging with a wait group for graceful shutdown.
- Simplified dashboard statistics handler to focus on key counts and request metrics.
- Removed key manager implementation and related interfaces.
- Updated proxy server to use atomic counters for round-robin key selection.
- Cleaned up unused types and configurations in types.go.
- Added package-lock.json for frontend dependencies.
This commit is contained in:
tbphp
2025-06-30 22:09:16 +08:00
parent 5f0990f22b
commit b9a833ceab
10 changed files with 130 additions and 669 deletions

View File

@@ -2,15 +2,12 @@
package types
import (
"time"
"github.com/gin-gonic/gin"
)
// ConfigManager defines the interface for configuration management
type ConfigManager interface {
GetServerConfig() ServerConfig
GetKeysConfig() KeysConfig
GetOpenAIConfig() OpenAIConfig
GetAuthConfig() AuthConfig
GetCORSConfig() CORSConfig
@@ -21,18 +18,6 @@ type ConfigManager interface {
ReloadConfig() error
}
// KeyManager defines the interface for API key management
type KeyManager interface {
LoadKeys() error
GetNextKey() (*KeyInfo, error)
RecordSuccess(key string)
RecordFailure(key string, err error)
GetStats() Stats
ResetBlacklist()
GetBlacklist() []BlacklistEntry
Close()
}
// ProxyServer defines the interface for proxy server
type ProxyServer interface {
HandleProxy(c *gin.Context)
@@ -49,14 +34,6 @@ type ServerConfig struct {
GracefulShutdownTimeout int `json:"gracefulShutdownTimeout"`
}
// KeysConfig represents keys configuration
type KeysConfig struct {
FilePath string `json:"filePath"`
StartIndex int `json:"startIndex"`
BlacklistThreshold int `json:"blacklistThreshold"`
MaxRetries int `json:"maxRetries"`
}
// OpenAIConfig represents OpenAI API configuration
type OpenAIConfig struct {
BaseURL string `json:"baseUrl"`
@@ -95,48 +72,3 @@ type LogConfig struct {
FilePath string `json:"filePath"`
EnableRequest bool `json:"enableRequest"`
}
// KeyInfo represents API key information
type KeyInfo struct {
Key string `json:"key"`
Index int `json:"index"`
Preview string `json:"preview"`
}
// Stats represents system statistics
type Stats struct {
CurrentIndex int64 `json:"currentIndex"`
TotalKeys int `json:"totalKeys"`
HealthyKeys int `json:"healthyKeys"`
BlacklistedKeys int `json:"blacklistedKeys"`
SuccessCount int64 `json:"successCount"`
FailureCount int64 `json:"failureCount"`
MemoryUsage MemoryUsage `json:"memoryUsage"`
}
// MemoryUsage represents memory usage statistics
type MemoryUsage struct {
Alloc uint64 `json:"alloc"`
TotalAlloc uint64 `json:"totalAlloc"`
Sys uint64 `json:"sys"`
NumGC uint32 `json:"numGC"`
LastGCTime string `json:"lastGCTime"`
NextGCTarget uint64 `json:"nextGCTarget"`
}
// BlacklistEntry represents a blacklisted key entry
type BlacklistEntry struct {
Key string `json:"key"`
Preview string `json:"preview"`
Reason string `json:"reason"`
BlacklistAt time.Time `json:"blacklistAt"`
FailCount int `json:"failCount"`
}
// RetryError represents retry error information
type RetryError struct {
StatusCode int `json:"statusCode"`
ErrorMessage string `json:"errorMessage"`
KeyIndex int `json:"keyIndex"`
Attempt int `json:"attempt"`
}