Split the monolithic config.go (~120KB) into focused modules: - auth.go: JWT, TOTP, Turnstile, RateLimit configs - billing.go: Billing and Pricing configs - database.go: Database and Redis configs - gateway.go: Gateway and Upstream configs - gateway_sub.go: Gateway sub-configurations - ops_and_cache.go: Ops and Cache configs - platforms.go: Platform-specific configs - security.go: Security-related configs - server.go: Server configuration - config_defaults.go: Default values - config_defaults_detail.go: Detailed defaults - config_helpers.go: Helper functions - config_validate.go: Validation logic - config_validate_gateway.go: Gateway validation This improves: - Code maintainability and readability - Faster compilation (smaller files) - Easier navigation and debugging - Better separation of concerns
99 lines
5.6 KiB
Go
99 lines
5.6 KiB
Go
package config
|
|
|
|
// GatewayOpenAIWSConfig OpenAI Responses WebSocket 配置
|
|
type GatewayOpenAIWSConfig struct {
|
|
ModeRouterV2Enabled bool `mapstructure:"mode_router_v2_enabled"`
|
|
IngressModeDefault string `mapstructure:"ingress_mode_default"`
|
|
Enabled bool `mapstructure:"enabled"`
|
|
OAuthEnabled bool `mapstructure:"oauth_enabled"`
|
|
APIKeyEnabled bool `mapstructure:"apikey_enabled"`
|
|
ForceHTTP bool `mapstructure:"force_http"`
|
|
AllowStoreRecovery bool `mapstructure:"allow_store_recovery"`
|
|
IngressPreviousResponseRecoveryEnabled bool `mapstructure:"ingress_previous_response_recovery_enabled"`
|
|
StoreDisabledConnMode string `mapstructure:"store_disabled_conn_mode"`
|
|
StoreDisabledForceNewConn bool `mapstructure:"store_disabled_force_new_conn"`
|
|
PrewarmGenerateEnabled bool `mapstructure:"prewarm_generate_enabled"`
|
|
|
|
ResponsesWebsockets bool `mapstructure:"responses_websockets"`
|
|
ResponsesWebsocketsV2 bool `mapstructure:"responses_websockets_v2"`
|
|
|
|
MaxConnsPerAccount int `mapstructure:"max_conns_per_account"`
|
|
MinIdlePerAccount int `mapstructure:"min_idle_per_account"`
|
|
MaxIdlePerAccount int `mapstructure:"max_idle_per_account"`
|
|
DynamicMaxConnsByAccountConcurrencyEnabled bool `mapstructure:"dynamic_max_conns_by_account_concurrency_enabled"`
|
|
OAuthMaxConnsFactor float64 `mapstructure:"oauth_max_conns_factor"`
|
|
APIKeyMaxConnsFactor float64 `mapstructure:"apikey_max_conns_factor"`
|
|
DialTimeoutSeconds int `mapstructure:"dial_timeout_seconds"`
|
|
ReadTimeoutSeconds int `mapstructure:"read_timeout_seconds"`
|
|
WriteTimeoutSeconds int `mapstructure:"write_timeout_seconds"`
|
|
PoolTargetUtilization float64 `mapstructure:"pool_target_utilization"`
|
|
QueueLimitPerConn int `mapstructure:"queue_limit_per_conn"`
|
|
EventFlushBatchSize int `mapstructure:"event_flush_batch_size"`
|
|
EventFlushIntervalMS int `mapstructure:"event_flush_interval_ms"`
|
|
PrewarmCooldownMS int `mapstructure:"prewarm_cooldown_ms"`
|
|
FallbackCooldownSeconds int `mapstructure:"fallback_cooldown_seconds"`
|
|
RetryBackoffInitialMS int `mapstructure:"retry_backoff_initial_ms"`
|
|
RetryBackoffMaxMS int `mapstructure:"retry_backoff_max_ms"`
|
|
RetryJitterRatio float64 `mapstructure:"retry_jitter_ratio"`
|
|
RetryTotalBudgetMS int `mapstructure:"retry_total_budget_ms"`
|
|
PayloadLogSampleRate float64 `mapstructure:"payload_log_sample_rate"`
|
|
|
|
LBTopK int `mapstructure:"lb_top_k"`
|
|
StickySessionTTLSeconds int `mapstructure:"sticky_session_ttl_seconds"`
|
|
SessionHashReadOldFallback bool `mapstructure:"session_hash_read_old_fallback"`
|
|
SessionHashDualWriteOld bool `mapstructure:"session_hash_dual_write_old"`
|
|
MetadataBridgeEnabled bool `mapstructure:"metadata_bridge_enabled"`
|
|
StickyResponseIDTTLSeconds int `mapstructure:"sticky_response_id_ttl_seconds"`
|
|
StickyPreviousResponseTTLSeconds int `mapstructure:"sticky_previous_response_ttl_seconds"`
|
|
|
|
SchedulerScoreWeights GatewayOpenAIWSSchedulerScoreWeights `mapstructure:"scheduler_score_weights"`
|
|
}
|
|
|
|
// GatewayOpenAIWSSchedulerScoreWeights 账号调度打分权重
|
|
type GatewayOpenAIWSSchedulerScoreWeights struct {
|
|
Priority float64 `mapstructure:"priority"`
|
|
Load float64 `mapstructure:"load"`
|
|
Queue float64 `mapstructure:"queue"`
|
|
ErrorRate float64 `mapstructure:"error_rate"`
|
|
TTFT float64 `mapstructure:"ttft"`
|
|
}
|
|
|
|
// GatewayUsageRecordConfig 使用量记录异步队列配置
|
|
type GatewayUsageRecordConfig struct {
|
|
WorkerCount int `mapstructure:"worker_count"`
|
|
QueueSize int `mapstructure:"queue_size"`
|
|
TaskTimeoutSeconds int `mapstructure:"task_timeout_seconds"`
|
|
OverflowPolicy string `mapstructure:"overflow_policy"` // drop/sample/sync
|
|
OverflowSamplePercent int `mapstructure:"overflow_sample_percent"` // 1-100
|
|
AutoScaleEnabled bool `mapstructure:"auto_scale_enabled"`
|
|
AutoScaleMinWorkers int `mapstructure:"auto_scale_min_workers"`
|
|
AutoScaleMaxWorkers int `mapstructure:"auto_scale_max_workers"`
|
|
AutoScaleUpQueuePercent int `mapstructure:"auto_scale_up_queue_percent"`
|
|
AutoScaleDownQueuePercent int `mapstructure:"auto_scale_down_queue_percent"`
|
|
AutoScaleUpStep int `mapstructure:"auto_scale_up_step"`
|
|
AutoScaleDownStep int `mapstructure:"auto_scale_down_step"`
|
|
AutoScaleCheckIntervalSeconds int `mapstructure:"auto_scale_check_interval_seconds"`
|
|
AutoScaleCooldownSeconds int `mapstructure:"auto_scale_cooldown_seconds"`
|
|
}
|
|
|
|
// TLSFingerprintConfig TLS 指纹伪装配置
|
|
type TLSFingerprintConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
Profiles map[string]TLSProfileConfig `mapstructure:"profiles"`
|
|
}
|
|
|
|
// TLSProfileConfig 单个 TLS 指纹模板配置
|
|
type TLSProfileConfig struct {
|
|
Name string `mapstructure:"name"`
|
|
EnableGREASE bool `mapstructure:"enable_grease"`
|
|
CipherSuites []uint16 `mapstructure:"cipher_suites"`
|
|
Curves []uint16 `mapstructure:"curves"`
|
|
PointFormats []uint16 `mapstructure:"point_formats"`
|
|
SignatureAlgorithms []uint16 `mapstructure:"signature_algorithms"`
|
|
ALPNProtocols []string `mapstructure:"alpn_protocols"`
|
|
SupportedVersions []uint16 `mapstructure:"supported_versions"`
|
|
KeyShareGroups []uint16 `mapstructure:"key_share_groups"`
|
|
PSKModes []uint16 `mapstructure:"psk_modes"`
|
|
Extensions []uint16 `mapstructure:"extensions"`
|
|
}
|