config

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound 是在键不存在时返回的错误
	ErrNotFound = errors.New("key not found")
	// ErrTypeMismatch 是在值类型与请求不匹配时返回的错误
	ErrTypeMismatch = errors.New("type mismatch")
	// ErrWatcherClosed 是在监视器关闭时返回的错误
	ErrWatcherClosed = errors.New("watcher closed")
)

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 是配置接口

func New

func New(opts ...Option) Config

New 创建一个配置

type Decoder

type Decoder func(src map[string]interface{}, dst interface{}) error

Decoder 是配置解码器函数类型

type KeyValue

type KeyValue struct {
	Key   string
	Value string
	// Format 是配置内容的格式,例如 "json", "yaml", "toml", "properties"
	Format string
}

KeyValue 是配置键值对

type Observer

type Observer func(string, Value)

Observer 是配置更改通知的观察者

type Option

type Option func(*options)

Option 是配置选项函数

func WithDecoder

func WithDecoder(d Decoder) Option

WithDecoder 设置解码器

func WithResolver

func WithResolver(r Resolver) Option

WithResolver 设置解析器

func WithSource

func WithSource(s ...Source) Option

WithSource 添加配置源

type Reader

type Reader interface {
	Merge(*KeyValue)
	Value(string) (Value, error)
	Values(string) (map[string]interface{}, error)
}

Reader 是配置读取器

type Resolver

type Resolver func(string) string

Resolver 是配置解析器函数类型

type Source

type Source interface {
	Load() ([]*KeyValue, error)
	Watch() (Watcher, error)
}

Source 是配置源接口

type Value

type Value interface {
	Bool() (bool, error)
	Int() (int64, error)
	Float() (float64, error)
	String() (string, error)
	Duration() (time.Duration, error)
	Slice() ([]Value, error)
	Map() (map[string]Value, error)
	Scan(interface{}) error
}

Value 是配置值接口

type ValueCallback

type ValueCallback func(string, Value)

ValueCallback 是配置值更改的回调

type Watcher

type Watcher interface {
	Next() ([]*KeyValue, error)
	Stop() error
}

Watcher 是配置更改的观察者

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL