Documentation
¶
Overview ¶
Package config contains viper config initialisation method.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConfigNotInitialized = errors.New("config not initialized") ErrEmptyKey = errors.New("key is empty") ErrNilVariable = errors.New("variable is nil") )
Config errors.
Functions ¶
func WatchVariable ¶ added in v0.22.0
func WatchVariable(key string, cb WatcherCallback) error
WatchVariable allows to set a callback func on a specific variable change.
Types ¶
type Config ¶ added in v0.22.0
type Config interface {
Get(key string) (Value, error)
WatchVariable(key string, cb WatcherCallback) error
}
Config describes a config client.
type StubConfig ¶ added in v0.22.0
type StubConfig struct{}
StubConfig implements Config.
func (StubConfig) Get ¶ added in v0.22.0
func (c StubConfig) Get(_ string) (Value, error)
Get returns nilValue and ErrConfigNotInitialized error.
func (StubConfig) WatchVariable ¶ added in v0.22.0
func (c StubConfig) WatchVariable(_ string, _ WatcherCallback) error
WatchVariable returns ErrConfigNotInitialized error.
type Value ¶ added in v0.22.0
type Value interface {
IsNil() bool
String() string
Bool() bool
Int() int
Int32() int32
Int64() int64
Uint() uint
Uint32() uint32
Uint64() uint64
Float64() float64
Time() time.Time
Duration() time.Duration
IntSlice() []int
StringSlice() []string
StringMap() map[string]interface{}
StringMapString() map[string]string
}
Value describes a config value.
type ViperConfig ¶ added in v0.22.0
type ViperConfig struct {
// contains filtered or unexported fields
}
ViperConfig implements Config interface for values.yaml.
func NewViperConfig ¶ added in v0.22.0
func NewViperConfig(opts *app.Options) (*ViperConfig, error)
NewViperConfig returns new viper config instance.
func (*ViperConfig) Get ¶ added in v0.22.0
func (c *ViperConfig) Get(key string) (Value, error)
Get returns a config Value associated with the key in viper config.
func (*ViperConfig) WatchVariable ¶ added in v0.22.0
func (c *ViperConfig) WatchVariable(key string, cb WatcherCallback) error
WatchVariable allows to set a callback func on a specific variable change in viper config.
type WatcherCallback ¶ added in v0.22.0
type WatcherCallback func(oldValue, newValue Value)
WatcherCallback is a callback function for a variable watcher.