config

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 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")
	ErrNilVariable          = errors.New("variable is nil")
)

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, 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.

func Get added in v0.22.0

func Get(key string) (Value, error)

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, 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.

Jump to

Keyboard shortcuts

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