-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_test.go
67 lines (54 loc) · 1.1 KB
/
get_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
60
61
62
63
64
65
66
67
package gostruct
import (
"fmt"
"testing"
)
type address struct {
Streat string
ZipCode string
State string
City []*city
Emails []string
Maps map[string]interface{}
In interface{}
}
type city struct {
Name string
InUS bool
Park *park
}
type park struct {
Name string
Location string
Maps map[string]interface{}
Emails []string
}
func TestGetStruct(t *testing.T) {
s := &address{}
s.Streat = "311 wind st"
s.ZipCode = "77479"
s.State = "Taxes"
s.Emails = []string{"[email protected]", "[email protected]"}
m := make(map[string]interface{})
m["dd"] = "dd"
m["cc"] = "cc"
m["bb"] = "bb"
s.Maps = m
s.City = append(s.City, &city{Name: "Sugar Land", InUS: true, Park: &park{Name: "Name", Location: "location", Maps: m}})
s.In = "string222"
field, err := GetField(s, "Emails")
if err != nil {
panic(err)
}
fmt.Println("Emails:", field)
field, err = GetField(s, "Emails[0]")
if err != nil {
panic(err)
}
fmt.Println("Emails[0]:", field)
field3, err := GetField(s, `City[0].Park.Maps`)
if err != nil {
panic(err)
}
fmt.Println("City[0].Park.Maps:", field3)
}