mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
add support json tag attribute for StructToMap function (#78)
This commit is contained in:
@@ -253,10 +253,11 @@ func StructToMap(value any) (map[string]any, error) {
|
||||
for i := 0; i < fieldNum; i++ {
|
||||
name := t.Field(i).Name
|
||||
tag := t.Field(i).Tag.Get("json")
|
||||
if regex.MatchString(name) && tag != "" {
|
||||
//result[name] = v.Field(i).Interface()
|
||||
result[tag] = v.Field(i).Interface()
|
||||
if tag == "" || strings.HasPrefix(tag, "-") || !regex.MatchString(name) {
|
||||
continue
|
||||
}
|
||||
tag = strings.Split(tag, ",")[0]
|
||||
result[tag] = v.Field(i).Interface()
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user