Fix panic related to env values from files and sprig dict funcs (#625)

* fix: 0.68.0: go panic w/ multiple bases/layers

Fixes #623

* fix: 0.64.1+: getOrNil/hasKey fails on Environment.Values with nested maps

Fixes #624
This commit is contained in:
KUOKA Yusuke
2019-05-30 15:41:00 +09:00
committed by GitHub
parent 591086dac9
commit b3f4586ed8
6 changed files with 200 additions and 14 deletions
+50
View File
@@ -0,0 +1,50 @@
package maputil
import "fmt"
func CastKeysToStrings(s interface{}) (map[string]interface{}, error) {
new := map[string]interface{}{}
switch src := s.(type) {
case map[interface{}]interface{}:
for k, v := range src {
var str_k string
switch typed_k := k.(type) {
case string:
str_k = typed_k
default:
return nil, fmt.Errorf("unexpected type of key in map: expected string, got %T: value=%v, map=%v", typed_k, typed_k, src)
}
var casted_v interface{}
switch typed_v := v.(type) {
case map[interface{}]interface{}:
tmp, err := CastKeysToStrings(typed_v)
if err != nil {
return nil, err
}
casted_v = tmp
default:
casted_v = typed_v
}
new[str_k] = casted_v
}
case map[string]interface{}:
for k, v := range src {
var casted_v interface{}
switch typed_v := v.(type) {
case map[interface{}]interface{}:
tmp, err := CastKeysToStrings(typed_v)
if err != nil {
return nil, err
}
casted_v = tmp
default:
casted_v = typed_v
}
new[k] = casted_v
}
}
return new, nil
}