config

package
v0.0.0-...-9eed78a Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Config

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

Config is config interface

func New

func New(opts ...Option) Config

New a config with options.

type Decoder

type Decoder func(*KeyValue, map[string]any) error

Decoder is config decoder

type KeyValue

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

KeyValue is config key value.

type Merge

type Merge func(src, dst any) error

Merge is config merge function

type Observer

type Observer func(string, Value)

Observer is config observer

type Option

type Option func(*options)

Option configs the options

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]any and stored in the config cache(map[string]any) if KeyValue.Format is empty,{KeyValue.Key : KeyValue.Value} will be stored in config cache(map[string]any)

func WithMergeFunc

func WithMergeFunc(m Merge) Option

WithMergeFunc with config merge func.

func WithResolveActualTypes

func WithResolveActualTypes(enableConvertToType bool) Option

WithResolveActualTypes with config resolver. bool input will enable conversion of config to data types

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]any) error

Resolver resolves 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(any) error
	Load() any
	Store(any)
}

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