Documentation
¶
Index ¶
- type KeyMap
- type Koanf
- func (ko *Koanf) All() map[string]interface{}
- func (ko *Koanf) Bool(path string) bool
- func (ko *Koanf) BoolMap(path string) map[string]bool
- func (ko *Koanf) Bools(path string) []bool
- func (ko *Koanf) Bytes(path string) []byte
- func (ko *Koanf) Copy() *Koanf
- func (ko *Koanf) Cut(path string) *Koanf
- func (ko *Koanf) Duration(path string) time.Duration
- func (ko *Koanf) Exists(path string) bool
- func (ko *Koanf) Float64(path string) float64
- func (ko *Koanf) Float64Map(path string) map[string]float64
- func (ko *Koanf) Float64s(path string) []float64
- func (ko *Koanf) Get(path string) interface{}
- func (ko *Koanf) Int(path string) int
- func (ko *Koanf) Int64(path string) int64
- func (ko *Koanf) Int64Map(path string) map[string]int64
- func (ko *Koanf) Int64s(path string) []int64
- func (ko *Koanf) IntMap(path string) map[string]int
- func (ko *Koanf) Ints(path string) []int
- func (ko *Koanf) KeyMap() KeyMap
- func (ko *Koanf) Keys() []string
- func (ko *Koanf) Load(p Provider, pa Parser) error
- func (ko *Koanf) MapKeys(path string) []string
- func (ko *Koanf) Merge(in *Koanf)
- func (ko *Koanf) Print()
- func (ko *Koanf) Raw() map[string]interface{}
- func (ko *Koanf) Sprint() string
- func (ko *Koanf) String(path string) string
- func (ko *Koanf) StringMap(path string) map[string]string
- func (ko *Koanf) Strings(path string) []string
- func (ko *Koanf) Time(path, layout string) time.Time
- func (ko *Koanf) Unmarshal(path string, o interface{}) error
- func (ko *Koanf) UnmarshalWithConf(path string, o interface{}, c UnmarshalConf) error
- type Parser
- type Provider
- type UnmarshalConf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyMap ¶
KeyMap represents a map of flattened delimited keys and the non-delimited parts as their slices. For nested keys, the map holds all levels of path combinations. For example, the nested structure `parent -> child -> key` will produce the map: parent.child.key => [parent, child, key] parent.child => [parent, child] parent => [parent]
type Koanf ¶
type Koanf struct {
// contains filtered or unexported fields
}
Koanf is the configuration apparatus.
func New ¶
New returns a new instance of Koanf. delim is the delimiter to use when specifying config key paths, for instance a . for `parent.child.key` or a / for `parent/child/key`.
func (*Koanf) All ¶
All returns a map of all flattened key paths and their values. Note that it uses maps.Copy to create a copy that uses json.Marshal which changes the numeric types to float64.
func (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) Cut ¶
Cut cuts the config map at a given key path into a sub map and returns a new Koanf instance with the cut config map loaded. For instance, if the loaded config has a path that looks like parent.child.sub.a.b, `Cut("parent.child")` returns a new Koanf instance with the config map `sub.a.b` where everything above `parent.child` are cut out.
func (*Koanf) Duration ¶
Duration returns the time.Duration value of a given key path assuming that the key contains a valid numeric value.
func (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) Get ¶
Get returns the raw, uncast interface{} value of a given key path in the config map. If the key path does not exist, nil is returned.
func (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) KeyMap ¶
KeyMap returns a map of flattened keys and the individual parts of the key as slices. eg: "parent.child.key" => ["parent", "child", "key"]
func (*Koanf) Keys ¶
Keys returns the slice of all flattened keys in the loaded configuration sorted alphabetically.
func (*Koanf) Load ¶
Load takes a Provider that either provides a parsed config map[string]interface{} in which case pa (Parser) can be nil, or raw bytes to be parsed, where a Parser can be provided to parse.
func (*Koanf) 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 (*Koanf) Merge ¶
Merge merges the config map of a given Koanf instance into the current instance.
func (*Koanf) Print ¶
func (ko *Koanf) Print()
Print prints a key -> value string representation of the config map with keys sorted alphabetically.
func (*Koanf) Raw ¶
Raw returns a copy of the full raw conf map. Note that it uses maps.Copy to create a copy that uses json.Marshal which changes the numeric types to float64.
func (*Koanf) Sprint ¶
Sprint returns a key -> value string representation of the config map with keys sorted alphabetically.
func (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) 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 (*Koanf) Unmarshal ¶
Unmarshal unmarshals a given key path into the given struct using the mapstructure lib. If no path is specified, the whole map is unmarshalled. `koanf` is the struct field tag used to match field names. To customize, use UnmarshalWithConf(). It uses the mitchellh/mapstructure package.
func (*Koanf) UnmarshalWithConf ¶
func (ko *Koanf) UnmarshalWithConf(path string, o interface{}, c UnmarshalConf) error
UnmarshalWithConf is like Unmarshal but takes configuration params in UnmarshalConf. See mitchellh/mapstructure's DecoderConfig for advanced customization of the unmarshal behaviour.
type Provider ¶
type Provider interface { // Read returns the entire configuration as raw []bytes to be parsed. // with a Parser. ReadBytes() ([]byte, error) // Read returns the prased configuration as a nested map[string]interface{}. // It is important to note that the string keys should not be flat delimited // keys like `parent.child.key`, but nested like `{parent: {child: {key: 1}}}`. Read() (map[string]interface{}, error) // Watch watches the source for changes, for instance, changes to a file, // and invokes a callback with an `event` interface, which a provider // is free to substitute with its own type, including nil. Watch(func(event interface{}, err error)) error }
Provider represents a configuration provider. Providers can read configuration from a source (file, HTTP etc.)
type UnmarshalConf ¶
type UnmarshalConf struct { // Tag is the struct field tag to unmarshal. // `koanf` is used if left empty. Tag string // If this is set to true, instead of unmarshalling nested structures // based on the key path, keys are taken literally to unmarshal into // a flat struct. For example: // “` // type MyStuff struct { // Child1Name string `koanf:"parent1.child1.name"` // Child2Name string `koanf:"parent2.child2.name"` // Type string `koanf:"json"` // } // “` FlatPaths bool DecoderConfig *mapstructure.DecoderConfig }
UnmarshalConf represents configuration options used by Unmarshal() to unmarshal conf maps into arbitrary structs.
Directories
¶
Path | Synopsis |
---|---|
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc.
|
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc. |
providers
|
|
env
Package env implements a koanf.Provider that reads environment variables as conf maps.
|
Package env implements a koanf.Provider that reads environment variables as conf maps. |
posflag
Package posflag implements a koanf.Provider that reads commandline parameters as conf maps using spf13/pflag, a POSIX compliant alternative to Go's stdlib flag package.
|
Package posflag implements a koanf.Provider that reads commandline parameters as conf maps using spf13/pflag, a POSIX compliant alternative to Go's stdlib flag package. |