From 852f19598decf975b506bfca75612bb69c271f4c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 19 Apr 2021 11:34:28 +0300 Subject: [PATCH] util/reflect: fix protobuf field name detection Signed-off-by: Vasiliy Tolstov --- util/reflect/reflect.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/util/reflect/reflect.go b/util/reflect/reflect.go index bb311723..c76386f4 100644 --- a/util/reflect/reflect.go +++ b/util/reflect/reflect.go @@ -70,7 +70,11 @@ func Merge(dst interface{}, mp map[string]interface{}, opts ...Option) error { tpart := strings.Split(tvalue, ",") switch tname { case "protobuf": - fname = tpart[3][5:] + for _, p := range tpart { + if idx := strings.Index(p, "name="); idx > 0 { + fname = p[idx:] + } + } default: fname = tpart[0] } @@ -231,13 +235,14 @@ func Merge(dst interface{}, mp map[string]interface{}, opts ...Option) error { default: err = ErrInvalidValue } + + if err != nil { + err = fmt.Errorf("%v key %v invalid val %v", err, fname, sval.Interface()) + } + } - if err != nil { - err = fmt.Errorf("%v key %v invalid val %v", err, fname, sval.Interface()) - } - - return err + return nil } func mergeBool(dval reflect.Value, sval reflect.Value) error {