Documentation ¶
Index ¶
- type Config
- func (c *Config) All() map[string]interface{}
- func (c *Config) Bool(path string) bool
- func (c *Config) BoolMap(path string) map[string]bool
- func (c *Config) Bools(path string) []bool
- func (c *Config) Bytes(path string) []byte
- func (c *Config) Cut(path string) *Config
- func (c *Config) Delimiter() string
- func (c *Config) Duration(path string) time.Duration
- func (c *Config) Exists(path string) bool
- func (c *Config) Float64(path string) float64
- func (c *Config) Float64Map(path string) map[string]float64
- func (c *Config) Float64s(path string) []float64
- func (c *Config) Get(path string) interface{}
- func (c *Config) Int(path string) int
- func (c *Config) Int64(path string) int64
- func (c *Config) Int64Map(path string) map[string]int64
- func (c *Config) Int64s(path string) []int64
- func (c *Config) IntMap(path string) map[string]int
- func (c *Config) Ints(path string) []int
- func (c *Config) KeyMap() map[string][]string
- func (c *Config) Keys() []string
- func (c *Config) LoadDefault(m map[string]interface{}) error
- func (c *Config) LoadEnv(pfx string) error
- func (c *Config) LoadFile(f string) (err error)
- func (c *Config) LoadFlag(f *flag.FlagSet) error
- func (c *Config) LoadJson(f string) error
- func (c *Config) LoadYaml(f string) error
- func (c *Config) MapKeys(path string) []string
- func (c *Config) Merge(config *Config) *Config
- func (c *Config) Print() *Config
- func (c *Config) Sprint() string
- func (c *Config) String(path string) string
- func (c *Config) StringMap(path string) map[string]string
- func (c *Config) Strings(path string) []string
- func (c *Config) Time(path, layout string) time.Time
- func (c *Config) Unmarshal(path string, out interface{}) error
- func (c *Config) WatchFile(f string, onReloaded func()) error
- func (c *Config) WatchJson(f string, onReloaded func()) error
- func (c *Config) WatchYaml(f string, onReloaded func()) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
The Config structure
func FromFile ¶
FromFile creates a new Config object from either a yaml or a json file - depending on the extension
func (*Config) All ¶
All returns a flat map of flattened key paths and their corresponding config values
func (*Config) Bool ¶
Bool returns the bool value of a given key path or false if the path does not exist or if the value is not a valid bool representation. Accepted string representations of bool are the ones supported by strconv.ParseBool.
func (*Config) BoolMap ¶
BoolMap returns the map[string]bool value of a given key path or an empty map[string]bool if the path does not exist or if the value is not a valid bool map.
func (*Config) Bools ¶
Bools returns the []bool slice value of a given key path or an empty []bool slice if the path does not exist or if the value is not a valid bool slice.
func (*Config) Bytes ¶
Bytes returns the []byte value of a given key path or an empty []byte slice if the path does not exist or if the value is not a valid string.
func (*Config) Cut ¶
Cut cuts the loaded nested conf map at the given path and returns a new Koanf instance with the children
func (*Config) Duration ¶
Duration returns the time.Duration value of a given key path assuming that the key contains a valid numeric value.
func (*Config) Float64 ¶
Float64 returns the float64 value of a given key path or 0 if the path does not exist or if the value is not a valid float64.
func (*Config) Float64Map ¶
Float64Map returns the map[string]float64 value of a given key path or an empty map[string]float64 if the path does not exist or if the value is not a valid float64 map.
func (*Config) Float64s ¶
Float64s returns the []float64 slice value of a given key path or an empty []float64 slice if the path does not exist or if the value is not a valid float64 slice.
func (*Config) Get ¶
Get returns the value for the given key path, and if it doesnt exist, returns nil
func (*Config) Int ¶
Int returns the int value of a given key path or 0 if the path does not exist or if the value is not a valid int.
func (*Config) Int64 ¶
Int64 returns the int64 value of a given key path or 0 if the path does not exist or if the value is not a valid int64.
func (*Config) Int64Map ¶
Int64Map returns the map[string]int64 value of a given key path or an empty map[string]int64 if the path does not exist or if the value is not a valid int64 map.
func (*Config) Int64s ¶
Int64s returns the []int64 slice value of a given key path or an empty []int64 slice if the path does not exist or if the value is not a valid int slice.
func (*Config) IntMap ¶
IntMap returns the map[string]int value of a given key path or an empty map[string]int if the path does not exist or if the value is not a valid int map.
func (*Config) Ints ¶
Ints returns the []int slice value of a given key path or an empty []int slice if the path does not exist or if the value is not a valid int slice.
func (*Config) KeyMap ¶
KeyMap returns a map of all possible key path combinations possible in the loaded nested conf map
func (*Config) Keys ¶
Keys returns the list of flattened key paths that can be used to access config values
func (*Config) LoadDefault ¶
LoadDefault loads default values from map eg
cfg.LoadDefault(map[string]interface{}{ "com": "COM4", "reset": false, "path": "/tmp", "timeperiod": 60, "debug.active": false, "debug.path": "/tmp", "websserver.active": true, "websserver.port": ":8080", "webservice.version": true, "webservice.winsol": true, "webservice.data": true, "webservice.download": true, })
func (*Config) LoadEnv ¶
LoadEnv loads config rom env variables Load environment variables and merge into the loaded config. pfx is the prefix to filter the env vars by. c.dl is the delimiter used to represent the key hierarchy in env vars. The (optional, or can be nil) function can be used to transform the env var names, for instance, to lowercase them.
For example, env vars: MYVAR_TYPE and MYVAR_PARENT1_CHILD1_NAME will be merged into the "type" and the nested "parent1.child1.name" keys in the config file here as we lowercase the key, replace `_` with `.` and strip the MYVAR_ prefix so that only "parent1.child1.name" remains.
func (*Config) MapKeys ¶
MapKeys returns a sorted 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.
func (*Config) Print ¶
Print prints a human readable copy of the flattened key paths and their values for debugging
func (*Config) Sprint ¶
Sprint returns a human readable copy of the flattened key paths and their values for debugging
func (*Config) String ¶
String returns the string value of a given key path or "" if the path does not exist or if the value is not a valid string.
func (*Config) StringMap ¶
StringMap returns the map[string]string value of a given key path or an empty map[string]string if the path does not exist or if the value is not a valid string map.
func (*Config) Strings ¶
Strings returns the []string slice value of a given key path or an empty []string slice if the path does not exist or if the value is not a valid string slice.
func (*Config) Time ¶
Time attempts to parse the value of a given key path and return time.Time representation. If the value is numeric, it is treated as a UNIX timestamp and if it's string, a parse is attempted with the given layout.
func (*Config) Unmarshal ¶
Unmarshal scans the given nested key path into a given struct (like json.Unmarshal)
func (*Config) WatchFile ¶
WatchFile watch loaded config file based on extension (either yaml or json) for changes, reloads it when changed and triggers onReloaded callback