Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = errors.New("key not found")
ErrNotFound 表示在配置中未找到指定键。
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config interface {
Load() error // 加载配置
Scan(v interface{}) error // 将配置解析到目标结构体
Value(key string) Value // 获取指定键的配置值
Watch(key string, o Observer) error // 监听指定键的变化
Close() error // 关闭配置监听器
}
Config 是配置接口。
type KeyValue ¶
type KeyValue struct {
// Key 是配置的键。
Key string
// Value 是配置的值,以字节切片的形式存储。
Value []byte
// Format 是配置值的格式,例如 JSON、YAML 等。
Format string
}
KeyValue 是配置的键值对。
type Option ¶
type Option func(*options)
Option 是配置的选项函数,用于设置 options。
func WithDecoder ¶
WithDecoder 设置自定义的配置解码器。 默认解码器行为: 如果 KeyValue.Format 不为空,则使用指定的格式解码 Value 为 map[string]interface{}。 如果 KeyValue.Format 为空,则直接存储 {KeyValue.Key : KeyValue.Value}。
func WithResolveActualTypes ¶
WithResolveActualTypes 配置占位符解析器,启用将配置值转换为实际数据类型的功能。
type Reader ¶
type Reader interface {
Merge(...*KeyValue) error // 合并配置数据
Value(string) (Value, bool) // 获取指定路径的配置值
Source() ([]byte, error) // 获取所有配置的 JSON 表示
Resolve() error // 执行配置解析器
}
Reader 是配置读取器接口。
type Source ¶
type Source interface {
// Load 方法从配置源加载配置键值对。
Load() ([]*KeyValue, error)
// Watch 方法创建一个监控器,用于监控配置源的变化。
Watch() (Watcher, error)
}
Source 是配置源的接口。
Click to show internal directories.
Click to hide internal directories.