conf

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

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

Conf is the configuration module.

func New

func New(name string) *Conf

New returns a new instance of Conf.

func (*Conf) Delete

func (cnf *Conf) Delete(key string) *Conf

Delete deletes the given key from configuration module.

The key should be a flattened path, with '.' as the delim.

func (*Conf) Get

func (cnf *Conf) Get(key string) interface{}

Get returns interface{} value of a given key path, or nil if key does not exist or is invalid.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) GetAll

func (cnf *Conf) GetAll() map[string]interface{}

GetAll merges the configured values with the default values and returns the data as a map.

func (*Conf) GetBool

func (cnf *Conf) GetBool(key string) bool

GetBool returns bool value of a given key path, or false if key does not exist or is invalid.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) GetFloat64

func (cnf *Conf) GetFloat64(key string) float64

GetFloat64 returns float64 value of a given key path, or 0 if key does not exist or is invalid.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) GetInt

func (cnf *Conf) GetInt(key string) int

GetInt returns int value of a given key path, or 0 if key does not exist or is invalid.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) GetMapKeys

func (cnf *Conf) GetMapKeys(key string) []string

GetMapKeys returns a string list of keys in a map addressed by the given path. If the path is not a map, an empty string slice is returned.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) GetParent

func (cnf *Conf) GetParent(name string) *Conf

GetParent returns parent of conf with given name. Returns nil if no parent of given name exists.

func (*Conf) GetString

func (cnf *Conf) GetString(key string) string

GetString returns string value of a given key path, or "" if key does not exist or is invalid.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) GetStrings

func (cnf *Conf) GetStrings(key string) []string

GetStrings returns []string slice value of a given key path, or "" if key does not exist or is invalid.

If given key doesn't exist in configuration module, the chained parent data is searched for the same.

func (*Conf) Has

func (cnf *Conf) Has(key string) bool

Has returns true if the given key exists in configuration.

func (*Conf) Load

func (cnf *Conf) Load(val map[string]interface{}) *Conf

Load merges given map into configuration data.

func (*Conf) LoadFile

func (cnf *Conf) LoadFile(path string) *Conf

LoadFile reads and loads data from file at given path to the configuration module. Does nothing if file doesn't exist.

Ensure the file at given path is of YAML format.

func (*Conf) Set

func (cnf *Conf) Set(key string, val interface{}) *Conf

Set updates the value at given key to val.

The key should be a flattened path, with '.' as the delim.

func (*Conf) SetDefault

func (cnf *Conf) SetDefault(key string, val interface{}) *Conf

SetDefault is like Set, but only updates the value at the given key, if the specified key does not exist.

The key should be a flattened path, with '.' as the delim.

func (*Conf) SetParent

func (cnf *Conf) SetParent(parentCnf *Conf) *Conf

SetParent sets the parent conf.

func (*Conf) WriteFile

func (cnf *Conf) WriteFile() *Conf

WriteFile overwrites data from the configuration module to the file last set using LoadConf(). Does nothing if configuration data is empty. Values from the default map are not written.

The written data is of YAML format.

Jump to

Keyboard shortcuts

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