config

package
v3.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config is an interface for dynamic configuration.

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

func Load added in v3.1.0

func Load(ctx context.Context, cs ...Config) error

Load loads config from config sources

func NewContext added in v3.1.0

func NewContext(ctx context.Context, c Config) context.Context

NewContext put store in context

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 value for changes
	//Watch(context.Context) (Watcher, error)
	// String returns config type name
	String() string
}

Config is an interface abstraction for dynamic configuration

var DefaultConfig Config = NewConfig()

DefaultConfig default config

func FromContext added in v3.1.0

func FromContext(ctx context.Context) (Config, bool)

FromContext returns store from context

func NewConfig

func NewConfig(opts ...Option) Config

NewConfig returns new default config source

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

type LoadOptions added in v3.4.0

type LoadOptions struct {
	Override bool
	Append   bool
}

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 AfterLoad added in v3.1.0

func AfterLoad(fn ...func(context.Context, Config) error) Option

AfterLoad run funcs after config load

func AfterSave added in v3.1.0

func AfterSave(fn ...func(context.Context, Config) error) Option

AfterSave run fncs after save

func AllowFail added in v3.1.0

func AllowFail(b bool) Option

AllowFail allows config source to fail

func BeforeLoad added in v3.1.0

func BeforeLoad(fn ...func(context.Context, Config) error) Option

BeforeLoad run funcs before config load

func BeforeSave added in v3.1.0

func BeforeSave(fn ...func(context.Context, Config) error) Option

BeforeSave run funcs before save

func Codec added in v3.1.0

func Codec(c codec.Codec) Option

Codec sets the source codec

func Context added in v3.1.0

func Context(ctx context.Context) Option

Context pass context

func Logger added in v3.1.0

func Logger(l logger.Logger) Option

Logger sets the logger

func Name added in v3.2.1

func Name(n string) Option

Name sets the name

func SetOption added in v3.1.0

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func Struct added in v3.1.0

func Struct(v interface{}) Option

Struct used as config

func StructTag added in v3.1.0

func StructTag(name string) Option

StructTag sets the struct tag that used for filling

func Tracer added in v3.1.6

func Tracer(t tracer.Tracer) Option

Tracer to be used for tracing

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

func NewOptions(opts ...Option) Options

NewOptions new options struct with filed values

type SaveOption added in v3.4.0

type SaveOption func(o *SaveOptions)

SaveOption function signature

type SaveOptions added in v3.4.0

type SaveOptions struct {
}

SaveOptions struct

func NewSaveOptions added in v3.4.0

func NewSaveOptions(opts ...SaveOption) SaveOptions

type Watcher

type Watcher interface {
	// Next() (, error)
	Stop() error
}

Watcher is the config watcher

Jump to

Keyboard shortcuts

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