-
Notifications
You must be signed in to change notification settings - Fork 15
/
helper.go
45 lines (39 loc) · 872 Bytes
/
helper.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
package onion
func searchStringMap(m map[string]interface{}, path ...string) (interface{}, bool) {
if len(path) == 0 {
return nil, false
}
v, ok := m[path[0]]
if !ok {
return nil, false
}
if len(path) == 1 {
return v, true
}
switch m := v.(type) {
case map[string]interface{}:
return searchStringMap(m, path[1:]...)
case map[interface{}]interface{}:
return searchInterfaceMap(m, path[1:]...)
}
return nil, false
}
func searchInterfaceMap(m map[interface{}]interface{}, path ...string) (interface{}, bool) {
if len(path) == 0 {
return nil, false
}
v, ok := m[path[0]]
if !ok {
return nil, false
}
if len(path) == 1 {
return v, true
}
switch m := v.(type) {
case map[string]interface{}:
return searchStringMap(m, path[1:]...)
case map[interface{}]interface{}:
return searchInterfaceMap(m, path[1:]...)
}
return nil, false
}