Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{}
n.Set([]string{"a", "b"}, 1)
n.SetByString("a.c.d", ".", "test")
n.SetByString("/e/f", "/", true)
var result interface{}
result, _ = n.Get([]string{"a", "c", "d"})
fmt.Println(result)
result, _ = n.GetByString("e/f", "/")
fmt.Println(result)
var b int
b, _ = n.GetInt([]string{"a", "b"})
fmt.Println(b)
}
Output: test true 1
Index ¶
- Variables
- type Nested
- func (n Nested) Delete(keys []string) error
- func (n Nested) DeleteByString(key, sep string) error
- func (n Nested) Get(keys []string) (value interface{}, err error)
- func (n Nested) GetBool(keys []string) (value bool, err error)
- func (n Nested) GetByString(key, sep string) (value interface{}, err error)
- func (n Nested) GetInt(keys []string) (value int, err error)
- func (n Nested) GetString(keys []string) (value string, err error)
- func (n Nested) Set(keys []string, value interface{})
- func (n Nested) SetByString(key, sep string, value interface{})
- func (n Nested) Walk(walkFn WalkFunc) error
- type WalkFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoSuchKey = errors.New("no such key") ErrUnmatchedType = errors.New("unmatched type") )
View Source
var SkipKey = errors.New("skip this key")
Functions ¶
This section is empty.
Types ¶
type Nested ¶
type Nested map[string]interface{}
func (Nested) Delete ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{"a": map[string]interface{}{"b": 1, "c": 2}}
n.Delete([]string{"a", "b"})
fmt.Printf("%v", n)
}
Output: map[a:map[c:2]]
func (Nested) DeleteByString ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{"a": map[string]interface{}{"b": 1, "c": 2}}
n.DeleteByString("a/b", "/")
fmt.Printf("%v", n)
}
Output: map[a:map[c:2]]
func (Nested) Get ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{"a": map[string]interface{}{"b": 1}}
result, _ := n.Get([]string{"a", "b"})
fmt.Printf("%v", result)
}
Output: 1
func (Nested) GetByString ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{"a": map[string]interface{}{"b": map[string]interface{}{"c": 2}}}
result, _ := n.GetByString("a.b.c", ".")
fmt.Printf("%v", result)
}
Output: 2
func (Nested) Set ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{}
n.Set([]string{"a", "b", "c"}, 1)
fmt.Printf("%v", n)
}
Output: map[a:map[b:map[c:1]]]
func (Nested) SetByString ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{}
n.SetByString("a.b.c", ".", "test")
fmt.Printf("%v", n)
}
Output: map[a:map[b:map[c:test]]]
func (Nested) Walk ¶
Example ¶
package main
import (
"fmt"
"github.com/knqyf263/nested"
)
func main() {
n := nested.Nested{}
n.Set([]string{"a", "b", "c"}, 1)
n.Set([]string{"d", "e"}, 2)
walkFn := func(keys []string, value interface{}) error {
fmt.Println(keys, value)
return nil
}
n.Walk(walkFn)
// [a] map[b:map[c:1]]
// [a b] map[c:1]
// [a b c] 1
// [d] map[e:2]
// [d e] 2
}
Click to show internal directories.
Click to hide internal directories.