rtconfig

package
v0.24.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyKey    = errors.New("key is empty")
	ErrNilVariable = errors.New("variable is nil")
)

Config errors.

Functions

func GetBool

func GetBool(key string) bool

GetBool returns the value associated with the key as a boolean.

func GetDuration

func GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration.

func GetFloat64

func GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64.

func GetInt

func GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func GetInt32

func GetInt32(key string) int32

GetInt32 returns the value associated with the key as an integer.

func GetInt64

func GetInt64(key string) int64

GetInt64 returns the value associated with the key as an integer.

func GetIntSlice

func GetIntSlice(key string) []int

GetIntSlice returns the value associated with the key as a slice of int values.

func GetString

func GetString(key string) string

GetString returns the value associated with the key as a string.

func GetStringMap

func GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as a map of interfaces.

func GetStringMapString

func GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func GetStringSlice

func GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func GetTime

func GetTime(key string) time.Time

GetTime returns the value associated with the key as time.

func GetUint

func GetUint(key string) uint

GetUint returns the value associated with the key as an unsigned integer.

func GetUint32

func GetUint32(key string) uint32

GetUint32 returns the value associated with the key as an unsigned integer.

func GetUint64

func GetUint64(key string) uint64

GetUint64 returns the value associated with the key as an unsigned integer.

func SetConfig added in v0.24.0

func SetConfig(config *Config)

SetConfig sets global config instance.

func WatchVariable

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

type Config struct {
	// contains filtered or unexported fields
}

Config is viper wrapper.

func GetConfig added in v0.24.0

func GetConfig() *Config

GetConfig gets global config instance.

func New added in v0.24.0

func New() *Config

New returns new Config instance.

func (*Config) Get added in v0.24.0

func (c *Config) Get(key string) (Value, error)

Get returns a config Value associated with the key in viper config.

func (*Config) SetConfigFile added in v0.24.0

func (c *Config) SetConfigFile(path, name, ext string) error

SetConfigFile sets config file.

func (*Config) SetDefaultConfigFile added in v0.24.0

func (c *Config) SetDefaultConfigFile(path, name, ext string) error

SetDefaultConfigFile sets default config file.

func (*Config) WatchConfig added in v0.24.0

func (c *Config) WatchConfig()

WatchConfig starts config watching.

func (*Config) WatchVariable added in v0.24.0

func (c *Config) WatchVariable(key string, cb WatcherCallback) error

WatchVariable allows to set a callback func on a specific variable change in viper config.

type Value

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 GetValue

func GetValue(key string) (Value, error)

GetValue returns a config Value associated with the key.

type WatcherCallback

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