mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-03 13:31:00 +07:00
chore: fix decode default value to interface
This commit is contained in:
parent
94f3ba4ee6
commit
6359215cb4
@ -67,7 +67,13 @@ func ParamParser(to reflect.Value, section *config_parser.Section, ignoreType []
|
|||||||
// Fill in default value before parsing section.
|
// Fill in default value before parsing section.
|
||||||
defaultValue, ok := structField.Tag.Lookup("default")
|
defaultValue, ok := structField.Tag.Lookup("default")
|
||||||
if ok {
|
if ok {
|
||||||
if !common.FuzzyDecode(field.Addr().Interface(), defaultValue) {
|
// Can we assign?
|
||||||
|
if field.Kind() == reflect.Interface ||
|
||||||
|
field.Type() == reflect.TypeOf(defaultValue) {
|
||||||
|
field.Set(reflect.ValueOf(defaultValue))
|
||||||
|
|
||||||
|
// Can we fuzzy decode?
|
||||||
|
} else if !common.FuzzyDecode(field.Addr().Interface(), defaultValue) {
|
||||||
return fmt.Errorf(`failed to decode default value of "%v"`, structField.Name)
|
return fmt.Errorf(`failed to decode default value of "%v"`, structField.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user