@@ -7,12 +7,20 @@ import (
7
7
8
8
func MapGetKV (v map [string ]interface {}, key string ) (interface {}, error ) {
9
9
var ok bool
10
+ var mcursor map [string ]interface {}
10
11
var cursor interface {} = v
12
+
11
13
parts := strings .Split (key , "." )
12
14
for i , part := range parts {
13
- cursor , ok = cursor .(map [string ]interface {})[part ]
15
+ sofar := strings .Join (parts [:i ], "." )
16
+
17
+ mcursor , ok = cursor .(map [string ]interface {})
18
+ if ! ok {
19
+ return nil , fmt .Errorf ("%s key is not a map" , sofar )
20
+ }
21
+
22
+ cursor , ok = mcursor [part ]
14
23
if ! ok {
15
- sofar := strings .Join (parts [:i ], "." )
16
24
return nil , fmt .Errorf ("%s key has no attributes" , sofar )
17
25
}
18
26
}
@@ -39,7 +47,7 @@ func MapSetKV(v map[string]interface{}, key string, value interface{}) error {
39
47
}
40
48
41
49
cursor , ok = mcursor [part ]
42
- if ! ok { // create map if this is empty
50
+ if ! ok || cursor == nil { // create map if this is empty or is null
43
51
mcursor [part ] = map [string ]interface {}{}
44
52
cursor = mcursor [part ]
45
53
}
0 commit comments