From 82e61fd9ddfc2fac9004ccaa476d078da70637a8 Mon Sep 17 00:00:00 2001 From: korzhao Date: Thu, 20 Jul 2023 15:01:39 +0800 Subject: [PATCH] optimize(errors): use reflect.MapRange() to avoid multiple loops --- errors.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/errors.go b/errors.go index 06b53c28..4342d108 100644 --- a/errors.go +++ b/errors.go @@ -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