Loader TestProcessContent with single file, defaults to map[string]interface{} -> struct

This commit is contained in:
DanB
2018-03-26 18:10:59 +02:00
parent a2ca4ef7e3
commit 9da53d5fdb
3 changed files with 163 additions and 7 deletions

View File

@@ -261,18 +261,27 @@ func UpdateStructWithIfaceMap(s interface{}, mp map[string]interface{}) (err err
if fld.IsValid() {
switch fld.Kind() {
case reflect.Bool:
if val == "" { // auto-populate defaults so we can parse empty strings
val = false
}
if valBool, err := IfaceAsBool(val); err != nil {
return err
} else {
fld.SetBool(valBool)
}
case reflect.Int, reflect.Int64:
if val == "" {
val = 0
}
if valInt, err := IfaceAsInt64(val); err != nil {
return err
} else {
fld.SetInt(valInt)
}
case reflect.Float64:
if val == "" {
val = 0.0
}
if valFlt, err := IfaceAsFloat64(val); err != nil {
return err
} else {