-
Notifications
You must be signed in to change notification settings - Fork 9
/
datamap.go
69 lines (55 loc) · 1.17 KB
/
datamap.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
68
69
package opvault
import (
"encoding/base64"
)
type dataMap map[string]interface{}
func (d dataMap) getBool(key string) bool {
val, _ := d[key].(bool)
return val
}
func (d dataMap) getInt(key string) int {
val, _ := d[key].(float64)
return int(val)
}
func (d dataMap) getInt64(key string) int64 {
val, _ := d[key].(float64)
return int64(val)
}
func (d dataMap) getString(key string) string {
val, _ := d[key].(string)
return val
}
func (d dataMap) getStringSlice(key string) []string {
val, _ := d[key].([]interface{})
if len(val) == 0 {
return []string{}
}
strs := []string{}
for _, i := range val {
if s, ok := i.(string); ok {
strs = append(strs, s)
}
}
return strs
}
func (d dataMap) getMapSlice(key string) []map[string]interface{} {
val, _ := d[key].([]interface{})
if len(val) == 0 {
return []map[string]interface{}{}
}
maps := []map[string]interface{}{}
for _, m := range val {
if m, ok := m.(map[string]interface{}); ok {
maps = append(maps, m)
}
}
return maps
}
func (d dataMap) getBytes(key string) []byte {
val, _ := d[key].(string)
if val == "" {
return nil
}
data, _ := base64.StdEncoding.DecodeString(val)
return data
}