From 307a08f50cc3a40d3c94af757c26979e0b05356a Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 4 May 2024 15:31:08 +0300 Subject: [PATCH] add more checks Signed-off-by: Vasiliy Tolstov --- util/reflect/struct.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/reflect/struct.go b/util/reflect/struct.go index 5fda8a84..10266261 100644 --- a/util/reflect/struct.go +++ b/util/reflect/struct.go @@ -111,10 +111,21 @@ func StructFieldByTag(src interface{}, tkey string, tval string) (interface{}, e // ZeroFieldByPath clean struct field by its path func ZeroFieldByPath(src interface{}, path string) error { + if src == nil { + return nil + } var err error val := reflect.ValueOf(src) + if IsEmpty(val) { + return nil + } + for _, p := range strings.Split(path, ".") { + if IsEmpty(val) { + return nil + } + val, err = structValueByName(val, p) if err != nil { return err