v2.7.3 Latest Latest

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 22 Imported by: 470




go get -u


go get -u


go get -u


go get -u




This section is empty.


View Source
var ErrNotFound = errors.New("key not found") // ErrNotFound is key not found.


This section is empty.


type Config

type Config interface {
	Load() error
	Scan(v interface{}) error
	Value(key string) Value
	Watch(key string, o Observer) error
	Close() error

Config is a config interface.

func New

func New(opts ...Option) Config

New a config with options.

type Decoder

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

Decoder is config decoder.

type KeyValue

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

KeyValue is config key value.

type Merge added in v2.7.2

type Merge func(dst, src interface{}) error

Merge is config merge func.

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 WithMergeFunc added in v2.7.2

func WithMergeFunc(m Merge) Option

WithMergeFunc with config merge func.

func WithResolver added in v2.0.1

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 added in v2.0.1

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

Resolver resolve placeholder in config.

type Source

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

Source is config 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
	Load() interface{}

Value is config value interface.

type Watcher

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

Watcher watches a source for changes.


Path Synopsis

Jump to

Keyboard shortcuts

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