Documentation
¶
Overview ¶
Package config provides configuration file loading and management functionality. Supports YAML format configuration files, and provides configuration validation and default value handling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppConfig ¶
type AppConfig struct {
Mode string `yaml:"mode"`
APIKey string `yaml:"api_key"` // API Key for authentication (sensitive information, recommend using environment variables)
}
AppConfig application configuration
type CacheConfig ¶
type CacheConfig struct {
TTL time.Duration `yaml:"ttl"`
UpdateInterval time.Duration `yaml:"update_interval"`
}
CacheConfig cache configuration
type CmdConfigData ¶
type CmdConfigData struct {
Port string // 16 bytes
Redis string // 16 bytes
RedisPassword string // 16 bytes
RedisEnabled bool // 1 byte (padding to 8 bytes)
RemoteConfig string // 16 bytes
RemoteKey string // 16 bytes
Mode string // 16 bytes
APIKey string // 16 bytes
TaskInterval int // 8 bytes
HTTPTimeout int // 8 bytes
HTTPMaxIdleConns int // 8 bytes
HTTPInsecureTLS bool // 1 byte (padding to 8 bytes)
}
CmdConfigData configuration data structure (used to convert to cmd.Config, avoid circular dependency)
type Config ¶
type Config struct {
Server ServerConfig `yaml:"server"`
Redis RedisConfig `yaml:"redis"`
Remote RemoteConfig `yaml:"remote"`
HTTP HTTPConfig `yaml:"http"`
Cache CacheConfig `yaml:"cache"`
RateLimit RateLimitConfig `yaml:"rate_limit"`
App AppConfig `yaml:"app"`
Task TaskConfig `yaml:"task"`
}
Config application configuration struct
func LoadFromFile ¶
LoadFromFile loads configuration from configuration file Supports YAML and TOML formats (determined by file extension) Priority: configuration file > environment variables > default values
func (*Config) GetRedisPassword ¶
GetRedisPassword gets Redis password (handles file reading)
func (*Config) ToCmdConfig ¶
func (c *Config) ToCmdConfig() *CmdConfigData
ToCmdConfig converts to cmd.Config format
func (*Config) ToLegacyConfig ¶
func (c *Config) ToLegacyConfig() *LegacyConfig
ToLegacyConfig converts to old Config format (maintains backward compatibility)
type HTTPConfig ¶
type HTTPConfig struct {
Timeout time.Duration `yaml:"timeout"`
MaxIdleConns int `yaml:"max_idle_conns"`
InsecureTLS bool `yaml:"insecure_tls"`
MaxRetries int `yaml:"max_retries"`
RetryDelay time.Duration `yaml:"retry_delay"`
}
HTTPConfig HTTP client configuration
type LegacyConfig ¶
type LegacyConfig struct {
Port string // 16 bytes
Redis string // 16 bytes
RedisPassword string // 16 bytes
RemoteConfig string // 16 bytes
RemoteKey string // 16 bytes
Mode string // 16 bytes
TaskInterval int // 8 bytes
HTTPTimeout int // 8 bytes
HTTPMaxIdleConns int // 8 bytes
HTTPInsecureTLS bool // 1 byte (padding to 8 bytes)
}
LegacyConfig old configuration format (for backward compatibility) Note: this type has the same structure as cmd.Config, but defined in a different package
type RateLimitConfig ¶
RateLimitConfig rate limit configuration
type RedisConfig ¶
type RedisConfig struct {
Addr string `yaml:"addr"` // 16 bytes
Password string `yaml:"password"` // 16 bytes
PasswordFile string `yaml:"password_file"` // 16 bytes
DB int `yaml:"db"` // 8 bytes
}
RedisConfig Redis configuration
type RemoteConfig ¶
type RemoteConfig struct {
URL string `yaml:"url"`
Key string `yaml:"key"`
Mode string `yaml:"mode"`
}
RemoteConfig remote configuration
type ServerConfig ¶
type ServerConfig struct {
Port string `yaml:"port"` // 16 bytes
ReadTimeout time.Duration `yaml:"read_timeout"` // 8 bytes
WriteTimeout time.Duration `yaml:"write_timeout"` // 8 bytes
ShutdownTimeout time.Duration `yaml:"shutdown_timeout"` // 8 bytes
IdleTimeout time.Duration `yaml:"idle_timeout"` // 8 bytes
MaxHeaderBytes int `yaml:"max_header_bytes"` // 8 bytes
}
ServerConfig server configuration
type TaskConfig ¶
TaskConfig task configuration