mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 05:16:35 +08:00
optimize(errors): use reflect.MapRange() to avoid multiple loops
This commit is contained in:
parent
d4a64265f2
commit
82e61fd9dd
@ -62,8 +62,8 @@ func (msg *Error) JSON() any {
|
||||
case reflect.Struct:
|
||||
return msg.Meta
|
||||
case reflect.Map:
|
||||
for _, key := range value.MapKeys() {
|
||||
jsonData[key.String()] = value.MapIndex(key).Interface()
|
||||
for iter := value.MapRange(); iter.Next(); {
|
||||
jsonData[iter.Key().String()] = iter.Value().Interface()
|
||||
}
|
||||
default:
|
||||
jsonData["meta"] = msg.Meta
|
||||
|
Loading…
x
Reference in New Issue
Block a user