Documentation
¶
Overview ¶
Package config provides configuration management with hot-reload support.
Index ¶
- func Load[T any](path string) T
- func LoadFrom[T any](src Source[T]) T
- func NewCfg[T any](path string) T
- type BaseConfig
- type CORSConfig
- type CasbinConfig
- type Config
- type FileSource
- type JWTConfig
- type KafkaConfig
- type LogConfig
- type LogFileConfig
- type MongoConfig
- type MysqlConfig
- type OtelConfig
- type RedisConfig
- type Source
- type Store
- type SystemConfig
- type WatchableSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseConfig ¶
type BaseConfig = Config
BaseConfig is an alias for Config for backward compatibility.
type CORSConfig ¶
type CORSConfig struct {
AllowOrigins []string `mapstructure:"allow_origins"`
AllowMethods []string `mapstructure:"allow_methods"`
AllowHeaders []string `mapstructure:"allow_headers"`
AllowCredentials bool `mapstructure:"allow_credentials"`
}
CORSConfig contains CORS settings.
type CasbinConfig ¶
type CasbinConfig struct {
Model string `mapstructure:"model"`
ModelFile string `mapstructure:"model_file"`
Enabled bool `mapstructure:"enabled"`
SkipPaths []string `mapstructure:"skip_paths"`
AdminUsers []string `mapstructure:"admin_users"`
}
CasbinConfig contains Casbin settings.
type Config ¶
type Config struct {
System SystemConfig `mapstructure:"system"`
Mysql MysqlConfig `mapstructure:"mysql"`
Redis RedisConfig `mapstructure:"redis"`
Mongodb MongoConfig `mapstructure:"mongodb"`
Kafka KafkaConfig `mapstructure:"kafka"`
Log LogConfig `mapstructure:"log"`
JWT JWTConfig `mapstructure:"jwt"`
CORS CORSConfig `mapstructure:"cors"`
Casbin CasbinConfig `mapstructure:"casbin"`
Otel OtelConfig `mapstructure:"otel"`
}
Config is the main application configuration.
type FileSource ¶
FileSource loads configuration from a local file.
type JWTConfig ¶
type JWTConfig struct {
Secret string `mapstructure:"secret"`
Expire time.Duration `mapstructure:"expire"`
SkipPaths []string `mapstructure:"skip_paths"`
Enabled bool `mapstructure:"enabled"`
}
JWTConfig contains JWT settings.
type KafkaConfig ¶
type KafkaConfig struct {
Brokers []string `mapstructure:"brokers"`
ClientID string `mapstructure:"client_id"`
Topic string `mapstructure:"topic"`
}
KafkaConfig contains Kafka connection settings.
type LogConfig ¶
type LogConfig struct {
Level string `mapstructure:"level"`
Format string `mapstructure:"format"` // json, text, color
Output string `mapstructure:"output"` // stdout, stderr
File LogFileConfig `mapstructure:"file"`
}
LogConfig contains logging settings.
type LogFileConfig ¶
type LogFileConfig struct {
Filename string `mapstructure:"filename"`
MaxSize int `mapstructure:"max_size"`
MaxBackups int `mapstructure:"max_backups"`
MaxAge int `mapstructure:"max_age"`
Compress bool `mapstructure:"compress"`
Format string `mapstructure:"format"`
}
LogFileConfig contains file logging settings.
type MongoConfig ¶
type MongoConfig struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
Database string `mapstructure:"database"`
}
MongoConfig contains MongoDB connection settings.
type MysqlConfig ¶
type MysqlConfig struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
Dbname string `mapstructure:"database"`
Database string `mapstructure:"database"` // Alias for Dbname
DockerHost string `mapstructure:"docker_host"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxLifetime int `mapstructure:"max_lifetime"`
}
MysqlConfig contains MySQL connection settings.
type OtelConfig ¶ added in v0.0.3
type OtelConfig struct {
Enabled bool `mapstructure:"enabled"` // 是否启用 OpenTelemetry
ServiceName string `mapstructure:"service_name"` // 服务名称
Environment string `mapstructure:"environment"` // 环境标识: dev, test, prod
OTLPEndpoint string `mapstructure:"otlp_endpoint"` // OTLP gRPC 端点地址
ExporterType string `mapstructure:"exporter_type"` // 导出器类型: otlp, stdout
SamplingRatio float64 `mapstructure:"sampling_ratio"` // 采样率: 0.0 - 1.0
}
OtelConfig contains OpenTelemetry settings.
type RedisConfig ¶
type RedisConfig struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Password string `mapstructure:"password"`
DB int `mapstructure:"database"`
Database int `mapstructure:"database"` // Alias for DB
PoolSize int `mapstructure:"pool_size"`
}
RedisConfig contains Redis connection settings.
type Store ¶
type Store[T any] struct { // contains filtered or unexported fields }
Store provides atomic read/update for configuration with hot-reload.
func (*Store[T]) Current ¶
func (s *Store[T]) Current() T
Current returns the current configuration.