config

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorUnchanged = errors.New("data not changed")

Functions

func GetConfigName

func GetConfigName(cfg Config) string

func Register

func Register(factory Factory)

Register 添加注册中心工厂对象

Types

type Config

type Config interface {
	Load() error
	Source(sources ...Source) error
	// Deprecated: As of Go v0.5.3, this function simply calls [ScanTo].
	Scan(v interface{}) error
	ScanTo(v interface{}) error
	Value(key string) Value
	Watch(key string, o Observer) error
	Close() error
	Path() string
	Get(key string) Config
	Root() Config
}

Config is a config interface.

func New

func New(opts ...Option) Config

New new a config with options.

type Decoder

type Decoder func(*KeyValue, map[string]interface{}) error

Decoder is config decoder.

type Factory

type Factory interface {
	Name() string
	Create(Config) (Source, error)
}

IFactory 注册中心构建器

type KeyValue

type KeyValue struct {
	Key    string
	Value  []byte
	Format string
}

KeyValue is config key value.

type Observer

type Observer func(string, Value)

Observer is config observer.

type Option

type Option func(*options)

Option is config option.

func WithDecoder

func WithDecoder(d Decoder) Option

WithDecoder with config decoder. DefaultDecoder behavior: If KeyValue.Format is non-empty, then KeyValue.Value will be deserialized into map[string]interface{} and stored in the config cache(map[string]interface{}) if KeyValue.Format is empty,{KeyValue.Key : KeyValue.Value} will be stored in config cache(map[string]interface{})

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger with config logger.

func WithResolver

func WithResolver(r Resolver) Option

WithResolver with config resolver.

func WithSource

func WithSource(s ...Source) Option

WithSource with config source.

type Reader

type Reader interface {
	Merge(...*KeyValue) error
	Value(string) (Value, bool)
	Source() ([]byte, error)
	Resolve() error
}

Reader is config reader.

type Resolver

type Resolver func(map[string]interface{}) error

Resolver resolve placeholder in config.

type Source

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

Source is config source.

func GetConfig

func GetConfig(cfg Config) (Source, error)

func NewStrSource

func NewStrSource(content string) Source

NewSource new a file source.

type Value

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

Value is config value interface.

type Watcher

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

Watcher watches a source for changes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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