Documentation ¶
Overview ¶
Package config is an interface for dynamic configuration.
Index ¶
- Variables
- func Load(ctx context.Context, cs []Config, opts ...LoadOption) error
- func NewContext(ctx context.Context, c Config) context.Context
- type Config
- type LoadOption
- type LoadOptions
- type Option
- func AfterLoad(fn ...func(context.Context, Config) error) Option
- func AfterSave(fn ...func(context.Context, Config) error) Option
- func AllowFail(b bool) Option
- func BeforeLoad(fn ...func(context.Context, Config) error) Option
- func BeforeSave(fn ...func(context.Context, Config) error) Option
- func Codec(c codec.Codec) Option
- func Context(ctx context.Context) Option
- func Logger(l logger.Logger) Option
- func Name(n string) Option
- func SetOption(k, v interface{}) Option
- func Struct(v interface{}) Option
- func StructTag(name string) Option
- func Tracer(t tracer.Tracer) Option
- type Options
- type SaveOption
- type SaveOptions
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCodecMissing is returned when codec needed and not specified ErrCodecMissing = errors.New("codec missing") // ErrInvalidStruct is returned when the target struct is invalid ErrInvalidStruct = errors.New("invalid struct specified") // ErrWatcherStopped is returned when source watcher has been stopped ErrWatcherStopped = errors.New("watcher stopped") )
var DefaultWatcherMaxInterval = 9 * time.Second
DefaultWatcherMinInterval default max interval for poll changes
var DefaultWatcherMinInterval = 5 * time.Second
DefaultWatcherMinInterval default min interval for poll changes
Functions ¶
Types ¶
type Config ¶
type Config interface { // Name returns name of config Name() string // Init the config Init(opts ...Option) error // Options in the config Options() Options // Load config from sources Load(context.Context, ...LoadOption) error // Save config to sources Save(context.Context, ...SaveOption) error // Watch a config for changes Watch(context.Context, ...WatchOption) (Watcher, error) // String returns config type name String() string }
Config is an interface abstraction for dynamic configuration
func FromContext ¶ added in v3.1.0
FromContext returns store from context
type LoadOption ¶ added in v3.4.0
type LoadOption func(o *LoadOptions)
LoadOption function signature
func LoadAppend ¶ added in v3.4.0
func LoadAppend(b bool) LoadOption
LoadAppend override values when load
func LoadOverride ¶ added in v3.4.0
func LoadOverride(b bool) LoadOption
LoadOverride override values when load
func LoadStruct ¶ added in v3.6.1
func LoadStruct(src interface{}) LoadOption
LoadStruct override struct for loading
type LoadOptions ¶ added in v3.4.0
LoadOptions struct
func NewLoadOptions ¶ added in v3.4.0
func NewLoadOptions(opts ...LoadOption) LoadOptions
type Option ¶
type Option func(o *Options)
Option function signature
func BeforeLoad ¶ added in v3.1.0
BeforeLoad run funcs before config load
func BeforeSave ¶ added in v3.1.0
BeforeSave run funcs before save
func SetOption ¶ added in v3.1.0
func SetOption(k, v interface{}) Option
SetOption returns a function to setup a context with given value
type Options ¶
type Options struct { // Struct holds the destination config struct Struct interface{} // Codec that used for load/save Codec codec.Codec // Tracer that will be used Tracer tracer.Tracer // Meter that will be used Meter meter.Meter // Logger that will be used Logger logger.Logger // Context used for external options Context context.Context // Name of the config Name string // StructTag name StructTag string // BeforeSave contains slice of funcs that runs before save BeforeSave []func(context.Context, Config) error // AfterLoad contains slice of funcs that runs after load AfterLoad []func(context.Context, Config) error // BeforeLoad contains slice of funcs that runs before load BeforeLoad []func(context.Context, Config) error // AfterSave contains slice of funcs that runs after save AfterSave []func(context.Context, Config) error // AllowFail flag to allow fail in config source AllowFail bool }
Options hold the config options
func NewOptions ¶ added in v3.1.0
NewOptions new options struct with filed values
type SaveOption ¶ added in v3.4.0
type SaveOption func(o *SaveOptions)
SaveOption function signature
func SaveStruct ¶ added in v3.6.1
func SaveStruct(src interface{}) SaveOption
SaveStruct override struct for save to config
type SaveOptions ¶ added in v3.4.0
type SaveOptions struct {
Struct interface{}
}
SaveOptions struct
func NewSaveOptions ¶ added in v3.4.0
func NewSaveOptions(opts ...SaveOption) SaveOptions
NewSaveOptions fill SaveOptions struct
type WatchOption ¶ added in v3.6.1
type WatchOption func(*WatchOptions)
func WatchCoalesce ¶ added in v3.6.1
func WatchCoalesce(b bool) WatchOption
WatchCoalesce controls watch event combining
func WatchContext ¶ added in v3.6.1
func WatchContext(ctx context.Context) WatchOption
WatchContext pass context
func WatchInterval ¶ added in v3.6.1
func WatchInterval(min, max time.Duration) WatchOption
WatchInterval specifies min and max time.Duration for pulling changes
func WatchStruct ¶ added in v3.6.1
func WatchStruct(src interface{}) WatchOption
WatchStruct overrides struct for fill
type WatchOptions ¶ added in v3.6.1
type WatchOptions struct { // Context used by non default options Context context.Context // Coalesce multiple events to one Coalesce bool // MinInterval specifies the min time.Duration interval for poll changes MinInterval time.Duration // MaxInterval specifies the max time.Duration interval for poll changes MaxInterval time.Duration // Struct for filling Struct interface{} }
WatchOptions struuct
func NewWatchOptions ¶ added in v3.6.1
func NewWatchOptions(opts ...WatchOption) WatchOptions