-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_test.go
59 lines (50 loc) · 867 Bytes
/
map_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package henge
import "fmt"
func ExampleValueConverter_Map() {
type In struct {
A int
B string
}
var in = In{
A: 125,
B: "25",
}
var s2 map[string]int
err := New(in).Map().Convert(&s2)
if err != nil {
return
}
fmt.Printf("%#v\n", s2)
// Output:
// map[string]int{"A":125, "B":25}
}
func ExampleValueConverter_Map_nested() {
type Nested2 struct {
Z int
}
type Nested1 struct {
Nested2
X string
Y int
}
type In struct {
A int
B Nested1
}
in := In{A: 1, B: Nested1{X: "x", Y: 2, Nested2: Nested2{Z: 3}}}
m, err := New(in, WithMapMaxDepth(1)).Map().Result()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(m)
}
m, err = New(in).Map().Result()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(m)
}
// Output:
// map[A:1 B:map[Nested2:{3} X:x Y:2]]
// map[A:1 B:map[Nested2:map[Z:3] X:x Y:2]]
}