Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Configuration ¶
type Configuration struct {
// Name 是应用名称。
Name string `mapstructure:"name" toml:"name"`
// Version 是应用配置声明的版本。
Version string `mapstructure:"version" toml:"version"`
// Web 保存 Web 监听配置。
Web web `mapstructure:"web" toml:"web"`
// Db 保存 PostgreSQL 配置;字段名为兼容既有调用保留。
Db db `mapstructure:"db" toml:"db"`
// Redis 保存 Redis 配置。
Redis redis `mapstructure:"redis" toml:"redis"`
// LogConf 保存日志输出配置。
LogConf logConf `mapstructure:"logConf" toml:"logConf"`
}
Configuration 定义脚手架内置的基础配置示例。 字段标签同时支持 Viper 的 mapstructure 和直接 TOML 解码。
var Config Configuration
Config 保留历史全局配置变量,供尚未迁移到业务自定义配置结构的调用方使用。 新项目应优先声明自己的配置实例,避免多个应用共享可变全局状态。
func (Configuration) Redact ¶
func (c Configuration) Redact() map[string]interface{}
Redact 输出不含密码的配置快照,供日志与诊断使用。
type Loader ¶
type Loader interface {
// LoadToStruct 将配置文件和环境变量映射到非 nil 结构体指针。
LoadToStruct(config interface{}) error
// SetConfigFileSearcher 设置配置文件名称和搜索目录,并立即尝试读取配置文件。
SetConfigFileSearcher(configName string, searchPath ...string) Loader
// EnableEnvSearcher 开启环境变量覆盖;非空前缀会生成 PREFIX_SECTION_FIELD 格式的变量名。
EnableEnvSearcher(envPrefix string) Loader
// Watch 监听配置文件变更,重载成功(含业务校验)后同步调用 handler。
// 必须在 LoadToStruct 之后调用;仅支持文件源的变更监听。
Watch(handler func()) error
}
Loader 定义配置文件和环境变量的链式加载能力。 链式配置阶段发生的错误会被暂存,并在 LoadToStruct 时统一返回给调用方。
Click to show internal directories.
Click to hide internal directories.