config

package
v0.22.0-rc1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config contains viper config initialisation method.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigNotInitialized = errors.New("config not initialized")
	ErrEmptyKey             = errors.New("key is empty")
)

Config errors.

Functions

func Init

func Init(opts *app.Options) error

Init initialise viper config.

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
	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(key string) Value

Get returns nilValue.

func (StubConfig) WatchVariable added in v0.22.0

func (c StubConfig) WatchVariable(key string, cb WatcherCallback) error

WatchVariable returns ErrConfigNotInitialized.

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.

func Get added in v0.22.0

func Get(key string) Value

Get returns a config Value associated with the key.

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

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.

Jump to

Keyboard shortcuts

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