Documentation ¶
Overview ¶
package maps provides some useful functions for working with maps.
Example ¶
package main import ( "fmt" "github.com/sraphs/maps" ) func main() { m := map[string]interface{}{ "a": map[string]interface{}{ "b": map[string]interface{}{ "nil": nil, "bool": true, "int_key": 1000, "float_key": 1000.1, "string_key": "string_value", "duration_key": 10000, }, }, } n := maps.Get(m, "a.b.nil").Load() b, _ := maps.Get(m, "a.b.bool").Bool() i, _ := maps.Get(m, "a.b.int_key").Int() f, _ := maps.Get(m, "a.b.float_key").Float() s, _ := maps.Get(m, "a.b.string_key").String() d, _ := maps.Get(m, "a.b.duration_key").Duration() fmt.Println(n) fmt.Println(b) fmt.Println(i) fmt.Println(f) fmt.Println(s) fmt.Println(d) }
Output: <nil> true 1000 1000.1 string_value 10µs
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotFound is key not found. ErrNotFound = errors.New("key not found") )
Functions ¶
Types ¶
type Value ¶
type Value interface { Bool() (bool, error) Int() (int64, error) Float() (float64, error) String() (string, error) Duration() (time.Duration, error) Slice() ([]Value, error) Map() (map[string]Value, error) Scan(interface{}) error Load() interface{} Store(interface{}) }
Value is config value interface.
Click to show internal directories.
Click to hide internal directories.