Documentation ¶
Overview ¶
Package dig provides a map[string]interface{} Mapping type that has ruby-like "dig" functionality.
It can be used for example to access and manipulate arbitary nested YAML/JSON structures.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mapping ¶
type Mapping map[string]interface{}
Mapping is a nested key-value map where the keys are strings and values are interface{}. In Ruby it is called a Hash (with string keys), in YAML it's called a "mapping".
func (*Mapping) Dig ¶
Dig is a simplistic implementation of a Ruby-like Hash.dig functionality.
It returns a value from a (deeply) nested tree structure.
Example ¶
h := Mapping{ "greeting": Mapping{ "target": "world", }, } fmt.Println("Hello,", h.Dig("greeting", "target"))
Output: Hello, world
func (*Mapping) DigMapping ¶
DigMapping always returns a mapping, creating missing or overwriting non-mapping branches in between
Example ¶
h := Mapping{} h.DigMapping("greeting")["target"] = "world" fmt.Println("Hello,", h.Dig("greeting", "target"))
Output: Hello, world
func (*Mapping) DigString ¶
DigString is like Dig but returns the value as string
Example ¶
h := Mapping{} h.DigMapping("greeting")["target"] = "world" fmt.Println("Hello,", h.DigString("greeting", "target"), "!") fmt.Println("Hello,", h.Dig("greeting", "non-existing"), "!") fmt.Println("Hello,", h.DigString("greeting", "non-existing"), "!")
Output: Hello, world ! Hello, <nil> ! Hello, !
func (*Mapping) UnmarshalYAML ¶
UnmarshalYAML for supporting yaml.Unmarshal