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) Marshal(p Parser) ([]byte, error)
- func (ko *Koanf) Merge(in *Koanf)
- func (ko *Koanf) MustBoolMap(path string) map[string]bool
- func (ko *Koanf) MustBools(path string) []bool
- func (ko *Koanf) MustBytes(path string) []byte
- func (ko *Koanf) MustDuration(path string) time.Duration
- func (ko *Koanf) MustFloat64(path string) float64
- func (ko *Koanf) MustFloat64Map(path string) map[string]float64
- func (ko *Koanf) MustFloat64s(path string) []float64
- func (ko *Koanf) MustInt(path string) int
- func (ko *Koanf) MustInt64(path string) int64
- func (ko *Koanf) MustInt64Map(path string) map[string]int64
- func (ko *Koanf) MustInt64s(path string) []int64
- func (ko *Koanf) MustIntMap(path string) map[string]int
- func (ko *Koanf) MustInts(path string) []int
- func (ko *Koanf) MustString(path string) string
- func (ko *Koanf) MustStringMap(path string) map[string]string
- func (ko *Koanf) MustStrings(path string) []string
- func (ko *Koanf) MustTime(path, layout string) time.Time
- 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 ¶ added in v0.2.0
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 ¶ added in v0.2.0
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 ¶ added in v0.2.0
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 ¶ added in v0.2.0
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 ¶ added in v0.4.0
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) Marshal ¶ added in v0.9.0
Marshal takes a Parser implementation and marshals the config map into bytes, for example, to TOML or JSON bytes.
func (*Koanf) Merge ¶
Merge merges the config map of a given Koanf instance into the current instance.
func (*Koanf) MustBoolMap ¶ added in v0.7.0
MustBoolMap returns the map[string]bool value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustBools ¶ added in v0.7.0
MustBools returns the []bool value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustBytes ¶ added in v0.7.0
MustBytes returns the []byte value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustDuration ¶ added in v0.7.0
MustDuration returns the time.Duration value of a given key path or panics if its not set or set to default value 0.
func (*Koanf) MustFloat64 ¶ added in v0.7.0
MustFloat64 returns the float64 value of a given key path or panics or panics if its not set or set to default value 0.
func (*Koanf) MustFloat64Map ¶ added in v0.7.0
MustFloat64Map returns the map[string]float64 value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustFloat64s ¶ added in v0.7.0
MustFloat64s returns the []Float64 slice value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustInt ¶ added in v0.7.0
MustInt returns the int value of a given key path or panics or panics if its not set or set to default value of 0.
func (*Koanf) MustInt64 ¶ added in v0.7.0
MustInt64 returns the int64 value of a given key path or panics if the value is not set or set to default value of 0.
func (*Koanf) MustInt64Map ¶ added in v0.7.0
MustInt64Map returns the map[string]int64 value of a given key path or panics if its not set or set to default value.
func (*Koanf) MustInt64s ¶ added in v0.7.0
MustInt64s returns the []int64 slice value of a given key path or panics if the value is not set or its default value.
func (*Koanf) MustIntMap ¶ added in v0.7.0
MustIntMap returns the map[string]int value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustInts ¶ added in v0.7.0
MustInts returns the []int slice value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustString ¶ added in v0.7.0
MustString returns the string value of a given key path or panics if its not set or set to default value "".
func (*Koanf) MustStringMap ¶ added in v0.7.0
MustStringMap returns the map[string]string value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustStrings ¶ added in v0.7.0
MustStrings returns the []string slice value of a given key path or panics if the value is not set or set to default value.
func (*Koanf) MustTime ¶ added in v0.7.0
MustTime 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. It panics if the parsed time is zero.
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 ¶ added in v0.2.0
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 ¶ added in v0.1.1
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 Parser ¶
type Parser interface { Unmarshal([]byte) (map[string]interface{}, error) Marshal(map[string]interface{}) ([]byte, error) }
Parser represents a configuration format parser.
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 |
---|---|
examples
module
|
|
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. |
parsers
|
|
hcl
Package hcl implements a koanf.Parser that parses Hashicorp HCL bytes as conf maps.
|
Package hcl implements a koanf.Parser that parses Hashicorp HCL bytes as conf maps. |
json
Package json implements a koanf.Parser that parses JSON bytes as conf maps.
|
Package json implements a koanf.Parser that parses JSON bytes as conf maps. |
toml
Package toml implements a koanf.Parser that parses TOML bytes as conf maps.
|
Package toml implements a koanf.Parser that parses TOML bytes as conf maps. |
yaml
Package yaml implements a koanf.Parser that parses YAML bytes as conf maps.
|
Package yaml implements a koanf.Parser that parses YAML bytes as conf maps. |
dotenv
Module
|
|
hjson
Module
|
|
kdl
Module
|
|
nestedtext
Module
|
|
providers
|
|
basicflag
Package basicflag implements a koanf.Provider that reads commandline parameters as conf maps using the Go's flag package.
|
Package basicflag implements a koanf.Provider that reads commandline parameters as conf maps using the Go's flag package. |
confmap
Package confmap implements a koanf.Provider that takes nested and flat map[string]interface{} config maps and provides them to koanf.
|
Package confmap implements a koanf.Provider that takes nested and flat map[string]interface{} config maps and provides them to koanf. |
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. |
file
Package file implements a koanf.Provider that reads raw bytes from files on disk to be used with a koanf.Parser to parse into conf maps.
|
Package file implements a koanf.Provider that reads raw bytes from files on disk to be used with a koanf.Parser to parse into 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. |
rawbytes
Package rawbytes implements a koanf.Provider that takes a []byte slice and provides it to koanf to be parsed by a koanf.Parser.
|
Package rawbytes implements a koanf.Provider that takes a []byte slice and provides it to koanf to be parsed by a koanf.Parser. |
s3
Package s3 implements a koanf.Provider that takes a []byte slice and provides it to koanf to be parsed by a koanf.Parser.
|
Package s3 implements a koanf.Provider that takes a []byte slice and provides it to koanf to be parsed by a koanf.Parser. |
structs
Package structs implements a koanf.Provider that takes a struct and tag and returns a nested config map (using fatih/structs) to provide it to koanf.
|
Package structs implements a koanf.Provider that takes a struct and tag and returns a nested config map (using fatih/structs) to provide it to koanf. |
appconfig
Module
|
|
cliflagv2
Module
|
|
consul
Module
|
|
etcd
Module
|
|
fs
Module
|
|
nats
Module
|
|
parameterstore
Module
|
|
vault
Module
|