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
123 lines
4.9 KiB
Go
123 lines
4.9 KiB
Go
package config
|
|
|
|
import "time"
|
|
|
|
// LogConfig 日志配置
|
|
type LogConfig struct {
|
|
Level string `mapstructure:"level"`
|
|
Format string `mapstructure:"format"`
|
|
ServiceName string `mapstructure:"service_name"`
|
|
Environment string `mapstructure:"env"`
|
|
Caller bool `mapstructure:"caller"`
|
|
StacktraceLevel string `mapstructure:"stacktrace_level"`
|
|
Output LogOutputConfig `mapstructure:"output"`
|
|
Rotation LogRotationConfig `mapstructure:"rotation"`
|
|
Sampling LogSamplingConfig `mapstructure:"sampling"`
|
|
}
|
|
|
|
type LogOutputConfig struct {
|
|
ToStdout bool `mapstructure:"to_stdout"`
|
|
ToFile bool `mapstructure:"to_file"`
|
|
FilePath string `mapstructure:"file_path"`
|
|
}
|
|
|
|
type LogRotationConfig struct {
|
|
MaxSizeMB int `mapstructure:"max_size_mb"`
|
|
MaxBackups int `mapstructure:"max_backups"`
|
|
MaxAgeDays int `mapstructure:"max_age_days"`
|
|
Compress bool `mapstructure:"compress"`
|
|
LocalTime bool `mapstructure:"local_time"`
|
|
}
|
|
|
|
type LogSamplingConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
Initial int `mapstructure:"initial"`
|
|
Thereafter int `mapstructure:"thereafter"`
|
|
}
|
|
|
|
// OpsConfig 运维监控配置
|
|
type OpsConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
UsePreaggregatedTables bool `mapstructure:"use_preaggregated_tables"`
|
|
Cleanup OpsCleanupConfig `mapstructure:"cleanup"`
|
|
MetricsCollectorCache OpsMetricsCollectorCacheConfig `mapstructure:"metrics_collector_cache"`
|
|
Aggregation OpsAggregationConfig `mapstructure:"aggregation"`
|
|
}
|
|
|
|
type OpsCleanupConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
Schedule string `mapstructure:"schedule"`
|
|
ErrorLogRetentionDays int `mapstructure:"error_log_retention_days"`
|
|
MinuteMetricsRetentionDays int `mapstructure:"minute_metrics_retention_days"`
|
|
HourlyMetricsRetentionDays int `mapstructure:"hourly_metrics_retention_days"`
|
|
}
|
|
|
|
type OpsAggregationConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
}
|
|
|
|
type OpsMetricsCollectorCacheConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
TTL time.Duration `mapstructure:"ttl"`
|
|
}
|
|
|
|
// APIKeyAuthCacheConfig API Key 认证缓存配置
|
|
type APIKeyAuthCacheConfig struct {
|
|
L1Size int `mapstructure:"l1_size"`
|
|
L1TTLSeconds int `mapstructure:"l1_ttl_seconds"`
|
|
L2TTLSeconds int `mapstructure:"l2_ttl_seconds"`
|
|
NegativeTTLSeconds int `mapstructure:"negative_ttl_seconds"`
|
|
JitterPercent int `mapstructure:"jitter_percent"`
|
|
Singleflight bool `mapstructure:"singleflight"`
|
|
}
|
|
|
|
// SubscriptionCacheConfig 订阅认证 L1 缓存配置
|
|
type SubscriptionCacheConfig struct {
|
|
L1Size int `mapstructure:"l1_size"`
|
|
L1TTLSeconds int `mapstructure:"l1_ttl_seconds"`
|
|
JitterPercent int `mapstructure:"jitter_percent"`
|
|
}
|
|
|
|
// SubscriptionMaintenanceConfig 订阅窗口维护后台任务配置
|
|
type SubscriptionMaintenanceConfig struct {
|
|
WorkerCount int `mapstructure:"worker_count"`
|
|
QueueSize int `mapstructure:"queue_size"`
|
|
}
|
|
|
|
// DashboardCacheConfig 仪表盘统计缓存配置
|
|
type DashboardCacheConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
KeyPrefix string `mapstructure:"key_prefix"`
|
|
StatsFreshTTLSeconds int `mapstructure:"stats_fresh_ttl_seconds"`
|
|
StatsTTLSeconds int `mapstructure:"stats_ttl_seconds"`
|
|
StatsRefreshTimeoutSeconds int `mapstructure:"stats_refresh_timeout_seconds"`
|
|
}
|
|
|
|
// DashboardAggregationConfig 仪表盘预聚合配置
|
|
type DashboardAggregationConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
IntervalSeconds int `mapstructure:"interval_seconds"`
|
|
LookbackSeconds int `mapstructure:"lookback_seconds"`
|
|
BackfillEnabled bool `mapstructure:"backfill_enabled"`
|
|
BackfillMaxDays int `mapstructure:"backfill_max_days"`
|
|
Retention DashboardAggregationRetentionConfig `mapstructure:"retention"`
|
|
RecomputeDays int `mapstructure:"recompute_days"`
|
|
}
|
|
|
|
// DashboardAggregationRetentionConfig 预聚合保留窗口
|
|
type DashboardAggregationRetentionConfig struct {
|
|
UsageLogsDays int `mapstructure:"usage_logs_days"`
|
|
UsageBillingDedupDays int `mapstructure:"usage_billing_dedup_days"`
|
|
HourlyDays int `mapstructure:"hourly_days"`
|
|
DailyDays int `mapstructure:"daily_days"`
|
|
}
|
|
|
|
// UsageCleanupConfig 使用记录清理任务配置
|
|
type UsageCleanupConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
MaxRangeDays int `mapstructure:"max_range_days"`
|
|
BatchSize int `mapstructure:"batch_size"`
|
|
WorkerIntervalSeconds int `mapstructure:"worker_interval_seconds"`
|
|
TaskTimeoutSeconds int `mapstructure:"task_timeout_seconds"`
|
|
}
|