-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_unexported.go
More file actions
36 lines (34 loc) · 844 Bytes
/
Copy pathnode_unexported.go
File metadata and controls
36 lines (34 loc) · 844 Bytes
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
package map2struct
import (
"strconv"
)
// ingestInterfaceSlice - for when we're working with []interface{}
func (e *Node) ingestInterfaceSlice(m []interface{}, key string) []string {
values := make([]string, 0, len(m))
for _, v := range m {
switch vv := v.(type) {
case map[string]interface{}:
sub := &Node{}
sub.Name = key
sub.Root = e
sub.Ingest(vv)
e.sub[key] = append(e.sub[key], sub)
case string:
value := vv
values = append(values, value)
case float64:
value := strconv.FormatFloat(vv, 'f', -1, 64)
values = append(values, value)
case []interface{}:
contents := e.ingestInterfaceSlice(vv, key)
e.array[key] = contents
case bool:
value := strconv.FormatBool(vv)
values = append(values, value)
case nil:
value := "NULL"
values = append(values, value)
}
}
return values
}