config

package
v0.0.0-...-505e429 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func DefaultDecoder

func DefaultDecoder(src *KeyValue, target map[string]interface{}) error

func DefaultResolver

func DefaultResolver(input map[string]interface{}) error

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 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. if source is a file, key is file name, value is the file content, format is file format suffix.

type Observer

type Observer func(string, Value)

Observer is config observer.

type Option

type Option func(*options)

Option is config option.

func WithSource

func WithSource(s ...Source) Option

type Reader

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

func NewReader

func NewReader(opts options) Reader

NewReader return a reader.

type Resolver

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{}
	Store(interface{})
}

type Watcher

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

Watcher is config watcher.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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