From 6359215cb4cc02cc44149910535f3956c96b23a7 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Fri, 3 Mar 2023 11:09:51 +0800 Subject: [PATCH] chore: fix decode default value to interface --- config/parser.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/parser.go b/config/parser.go index cbc43ba..f422423 100644 --- a/config/parser.go +++ b/config/parser.go @@ -67,7 +67,13 @@ func ParamParser(to reflect.Value, section *config_parser.Section, ignoreType [] // Fill in default value before parsing section. defaultValue, ok := structField.Tag.Lookup("default") 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) } }