@@ -51,15 +51,31 @@ func MergeMap(first map[interface{}]interface{}, second map[interface{}]interfac
51
51
// fmt.Printf("first type:%v", reflect.TypeOf(first[k]))
52
52
// fmt.Printf("second type:%v", reflect.TypeOf(second[k]))
53
53
if reflect .TypeOf (second [k ]) != reflect .TypeOf (first [k ]) {
54
+ // fmt.Printf("if first: %v, second: :%v\n", first[k], second[k])
54
55
first [k ] = v
55
- // fmt.Printf("v:%v\n", v)
56
56
} else if reflect .TypeOf (first [k ]) == reflect .TypeOf (map [interface {}]interface {}{}) {
57
57
//merge maps
58
+ // fmt.Printf("else if first: %v, second: :%v\n", first[k], second[k])
58
59
first [k ] = MergeMap (first [k ].(map [interface {}]interface {}), second [k ].(map [interface {}]interface {}))
59
60
} else {
60
61
//for other types,replace it with value in first map.
62
+ // fmt.Printf("else first: %v, second: :%v\n", v, second[k])
63
+ first [k ] = second [k ]
64
+ }
65
+ }
66
+
67
+ for k , v := range second {
68
+ if reflect .TypeOf (second [k ]) != reflect .TypeOf (first [k ]) {
69
+ // fmt.Printf("if first: %v, second: :%v\n", first[k], second[k])
70
+ first [k ] = v
71
+ } else if reflect .TypeOf (first [k ]) == reflect .TypeOf (map [interface {}]interface {}{}) {
72
+ //merge maps
73
+ // fmt.Printf("else if first: %v, second: :%v\n", first[k], second[k])
74
+ first [k ] = MergeMap (first [k ].(map [interface {}]interface {}), second [k ].(map [interface {}]interface {}))
75
+ } else {
76
+ //for other types,replace it with value in second map.
77
+ // fmt.Printf("else first: %v, second: :%v\n", v, second[k])
61
78
first [k ] = second [k ]
62
- // fmt.Printf("cover,v:%v\n", v)
63
79
}
64
80
}
65
81
0 commit comments