Documentation ¶
Overview ¶
Package config provides configuration management for the application. It includes structures for various configuration aspects such as system settings, logging, databases, caching, and external service integrations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { Driver string `json:"driver"` // Cache driver Prefix string `json:"prefix"` // Cache key prefix }
Cache defines caching configuration options.
type Config ¶
type Config struct { System SysConfig `json:"system"` // System-wide configuration Log LogConfig `json:"log"` // Logging configuration Databases []Database `json:"databases"` // Database configurations Cache Cache `json:"cache"` // Caching configuration Redis []Redis `json:"redis"` // Redis configurations Kafka Kafka `json:"kafka"` // Kafka configuration Monitor Monitor `json:"monitor"` // Monitoring configuration Notify Notify `json:"notify"` // Notify configuration }
Config represents the entire application configuration.
func Get ¶
func Get() *Config
Get returns the global configuration object. This function should be called after LoadConfig has been executed.
Returns:
- *Config: A pointer to the global configuration structure.
Example usage:
cfg := Get() fmt.Printf("Application name: %s\n", cfg.System.Name)
func LoadConfig ¶
LoadConfig loads the application configuration from a JSON file. It determines the configuration file to load based on the runtime environment, unmarshal the JSON content into a Config struct, and performs some post-processing.
The function uses environment variables to determine the runtime environment and application name. If these are not set, it falls back to default values.
Returns:
- *Config: A pointer to the loaded configuration structure.
- error: An error if any occurred during the loading process.
type Database ¶
type Database struct { Enable bool `json:"enable"` // Database enable flag DbType string `json:"db_type"` // Database type DbHost string `json:"db_host"` // Database host DbName string `json:"db_name"` // Database name DbUsername string `json:"db_username,omitempty"` // Database username DbPassword string `json:"db_password,omitempty"` // Database password DbMaxIdleConn int `json:"db_max_idle_conn,omitempty"` // Maximum number of idle connections in the pool DbMaxOpenConn int `json:"db_max_open_conn,omitempty"` // Maximum number of open connections to the database DbMaxLifetime time.Duration `json:"db_max_lifetime,omitempty"` // Maximum amount of time a connection may be reused (in hours) AuthMechanism string `json:"auth_mechanism"` // Authentication mechanism (for MongoDB) }
Database defines database configuration options.
type Kafka ¶
type Kafka struct { Brokers []string `json:"brokers"` // Kafka broker addresses MaxRetry int `json:"max_retry"` // Maximum number of retries ClientID string `json:"client_id"` // Kafka client ID ProducerEnable bool `json:"producer_enable"` // Producer enable flag ConsumerEnable bool `json:"consumer_enable"` // Consumer enable flag ConsumerGroup string `json:"consumer_group"` // Consumer group name ConsumerTopics []string `json:"consumer_topics"` // Topics to consume ConsumerAutoSubmit bool `json:"consumer_auto_submit"` // Auto-submit consumer offsets flag }
Kafka defines Kafka configuration options.
type Lark ¶
type Lark struct { Enable bool `json:"enable"` DefaultSendChannelName string `json:"default_send_channel_name"` ChannelSize int `json:"channel_size"` PoolSize int `json:"pool_size"` BotWebhooks map[string]string `json:"bot_webhooks"` Larks map[string]LarkApp `json:"larks"` }
Lark defines Lark configuration options.
type LarkApp ¶
type LarkApp struct { AppType string `json:"app_type"` AppID string `json:"app_id"` AppSecret string `json:"app_secret"` }
LarkApp defines Lark application configuration options.
type LogConfig ¶
type LogConfig struct { Driver string `json:"driver"` // Log driver: "stdout" or "file" Level string `json:"level"` // Log level: "debug", "info", "warn", "error", "fatal" LogPath string `json:"log_path"` // Log file path (only used when Driver is "file") }
LogConfig defines logging configuration options.
type Monitor ¶
type Monitor struct {
PanicRobot PanicRobot `json:"panic_robot"` // Panic robot configuration
}
Monitor defines monitoring configuration options.
type Notify ¶
type Notify struct { DefaultChannel string `json:"default_channel"` DefaultLevel string `json:"default_level"` Lark Lark `json:"lark"` }
Notify defines notification configuration options.
type PanicRobot ¶
type PanicRobot struct { Enable bool `json:"enable"` // Panic robot enable flag Wechat robotConfig `json:"wechat"` // WeChat's configuration for panic reporting Feishu robotConfig `json:"feishu"` // Feishu configuration for panic reporting }
PanicRobot defines configuration for panic reporting.
type Redis ¶
type Redis struct { Name string `json:"name"` // Redis connection name Enable bool `json:"enable"` // Redis enable flag Host string `json:"host"` // Redis host Auth string `json:"auth"` // Redis authentication MaxIdle int `json:"max_idle"` // Maximum number of idle connections in the pool MaxActive int `json:"max_active"` // Maximum number of connections allocated by the pool at a given time IdleTimeout time.Duration `json:"idle_timeout"` // Close connections after remaining idle for this duration (in minutes) Prefix string `json:"prefix"` // Redis key prefix DB int `json:"db"` // Redis database number }
Redis defines Redis configuration options.
type SysConfig ¶
type SysConfig struct { Name string `json:"name"` // Application name RunMode string `json:"run_mode"` // Running mode HTTPPort string `json:"http_port"` // HTTP server port ReadTimeout time.Duration `json:"read_timeout"` // Maximum request timeout WriteTimeout time.Duration `json:"write_timeout"` // Maximum response timeout Version string `json:"version"` // Application version RootPath string `json:"root_path"` // Root directory path DebugMode bool `json:"debug_mode"` // Debug mode flag LangDir string `json:"lang_dir"` // Language files directory DefaultLang string `json:"default_lang"` // Default language EnvKey string `json:"env_key"` // Environment key for reading runtime environment JwtSecret string `json:"jwt_secret"` // JWT secret for authentication TokenExpire time.Duration `json:"token_expire"` // JWT token expiration time (in seconds) Env string `json:"env"` // Runtime environment }
SysConfig defines system-wide configuration options.