util/reflect: fix protobuf field name detection

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-04-19 11:34:28 +03:00
parent 6537b35773
commit 852f19598d

View File

@ -70,7 +70,11 @@ func Merge(dst interface{}, mp map[string]interface{}, opts ...Option) error {
tpart := strings.Split(tvalue, ",") tpart := strings.Split(tvalue, ",")
switch tname { switch tname {
case "protobuf": case "protobuf":
fname = tpart[3][5:] for _, p := range tpart {
if idx := strings.Index(p, "name="); idx > 0 {
fname = p[idx:]
}
}
default: default:
fname = tpart[0] fname = tpart[0]
} }
@ -231,13 +235,14 @@ func Merge(dst interface{}, mp map[string]interface{}, opts ...Option) error {
default: default:
err = ErrInvalidValue err = ErrInvalidValue
} }
if err != nil {
err = fmt.Errorf("%v key %v invalid val %v", err, fname, sval.Interface())
}
} }
if err != nil { return nil
err = fmt.Errorf("%v key %v invalid val %v", err, fname, sval.Interface())
}
return err
} }
func mergeBool(dval reflect.Value, sval reflect.Value) error { func mergeBool(dval reflect.Value, sval reflect.Value) error {