1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 08:12:26 +08:00

fix: fix StructToUrlValues failed when tag contain omitempty

This commit is contained in:
dudaodong
2023-03-06 17:07:57 +08:00
parent 71aa91a58d
commit 6a9eb645bb
5 changed files with 84 additions and 42 deletions

View File

@@ -297,7 +297,11 @@ func StructToUrlValues(targetStruct any) url.Values {
for i := 0; i < fieldNum; i++ {
name := rt.Field(i).Name
tag := rt.Field(i).Tag.Get("json")
// if regex.MatchString(name) && tag != "" && !strings.Contains(tag, "omitempty"){
if regex.MatchString(name) && tag != "" {
if strings.Contains(tag, "omitempty") {
tag = strings.Split(tag, ",")[0]
}
result.Add(tag, fmt.Sprintf("%v", rv.Field(i).Interface()))
}
}