optimize(errors): use reflect.MapRange() to avoid multiple loops

This commit is contained in:
korzhao 2023-07-20 15:01:39 +08:00
parent d4a64265f2
commit 82e61fd9dd
1 changed files with 2 additions and 2 deletions

View File

@ -62,8 +62,8 @@ func (msg *Error) JSON() any {
case reflect.Struct: case reflect.Struct:
return msg.Meta return msg.Meta
case reflect.Map: case reflect.Map:
for _, key := range value.MapKeys() { for iter := value.MapRange(); iter.Next(); {
jsonData[key.String()] = value.MapIndex(key).Interface() jsonData[iter.Key().String()] = iter.Value().Interface()
} }
default: default:
jsonData["meta"] = msg.Meta jsonData["meta"] = msg.Meta