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
43 lines
2.1 KiB
Go
43 lines
2.1 KiB
Go
package config
|
||
|
||
import "fmt"
|
||
|
||
// ServerConfig HTTP 服务端配置
|
||
type ServerConfig struct {
|
||
Host string `mapstructure:"host"`
|
||
Port int `mapstructure:"port"`
|
||
Mode string `mapstructure:"mode"` // debug/release
|
||
FrontendURL string `mapstructure:"frontend_url"` // 前端基础 URL,用于生成邮件中的外部链接
|
||
ReadHeaderTimeout int `mapstructure:"read_header_timeout"` // 读取请求头超时(秒)
|
||
IdleTimeout int `mapstructure:"idle_timeout"` // 空闲连接超时(秒)
|
||
TrustedProxies []string `mapstructure:"trusted_proxies"` // 可信代理列表(CIDR/IP)
|
||
MaxRequestBodySize int64 `mapstructure:"max_request_body_size"` // 全局最大请求体限制
|
||
H2C H2CConfig `mapstructure:"h2c"` // HTTP/2 Cleartext 配置
|
||
}
|
||
|
||
// H2CConfig HTTP/2 Cleartext 配置
|
||
type H2CConfig struct {
|
||
Enabled bool `mapstructure:"enabled"` // 是否启用 H2C
|
||
MaxConcurrentStreams uint32 `mapstructure:"max_concurrent_streams"` // 最大并发流数量
|
||
IdleTimeout int `mapstructure:"idle_timeout"` // 空闲超时(秒)
|
||
MaxReadFrameSize int `mapstructure:"max_read_frame_size"` // 最大帧大小(字节)
|
||
MaxUploadBufferPerConnection int `mapstructure:"max_upload_buffer_per_connection"` // 每个连接的上传缓冲区(字节)
|
||
MaxUploadBufferPerStream int `mapstructure:"max_upload_buffer_per_stream"` // 每个流的上传缓冲区(字节)
|
||
}
|
||
|
||
// CORSConfig 跨域配置
|
||
type CORSConfig struct {
|
||
AllowedOrigins []string `mapstructure:"allowed_origins"`
|
||
AllowCredentials bool `mapstructure:"allow_credentials"`
|
||
}
|
||
|
||
// ConcurrencyConfig 并发配置
|
||
type ConcurrencyConfig struct {
|
||
// PingInterval: 并发等待期间的 SSE ping 间隔(秒)
|
||
PingInterval int `mapstructure:"ping_interval"`
|
||
}
|
||
|
||
func (s ServerConfig) Address() string {
|
||
return fmt.Sprintf("%s:%d", s.Host, s.Port)
|
||
}
|