From 956205311bfee87597393c2e12d6e0178e1c0e80 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 28 May 2025 13:49:33 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20use=20maps.Cop?= =?UTF-8?q?y=20to=20simplify=20code=20(#3490)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- binder/mapping.go | 5 ++--- client/request.go | 9 +++------ middleware/logger/tags.go | 5 ++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/binder/mapping.go b/binder/mapping.go index 993c898c..7cebff5c 100644 --- a/binder/mapping.go +++ b/binder/mapping.go @@ -3,6 +3,7 @@ package binder import ( "errors" "fmt" + "maps" "mime/multipart" "reflect" "strings" @@ -115,9 +116,7 @@ func parseToMap(ptr any, data map[string][]string) error { return ErrMapNotConvertable } - for k, v := range data { - newMap[k] = v - } + maps.Copy(newMap, data) case reflect.String, reflect.Interface: newMap, ok := ptr.(map[string]string) if !ok { diff --git a/client/request.go b/client/request.go index daa7e60b..26d1f8f0 100644 --- a/client/request.go +++ b/client/request.go @@ -6,6 +6,7 @@ import ( "errors" "io" "iter" + "maps" "path/filepath" "reflect" "slices" @@ -748,9 +749,7 @@ func (c Cookie) SetCookie(key, val string) { // SetCookies sets multiple cookies from a map. func (c Cookie) SetCookies(m map[string]string) { - for k, v := range m { - c[k] = v - } + maps.Copy(c, m) } // SetCookiesWithStruct sets cookies from a struct. @@ -800,9 +799,7 @@ func (p PathParam) SetParam(key, val string) { // SetParams sets multiple path parameters from a map. func (p PathParam) SetParams(m map[string]string) { - for k, v := range m { - p[k] = v - } + maps.Copy(p, m) } // SetParamsWithStruct sets multiple path parameters from a struct. diff --git a/middleware/logger/tags.go b/middleware/logger/tags.go index 25f1a48f..67a10a51 100644 --- a/middleware/logger/tags.go +++ b/middleware/logger/tags.go @@ -2,6 +2,7 @@ package logger import ( "fmt" + "maps" "strings" "github.com/gofiber/fiber/v3" @@ -204,9 +205,7 @@ func createTagMap(cfg *Config) map[string]LogFunc { }, } // merge with custom tags from user - for k, v := range cfg.CustomTags { - tagFunctions[k] = v - } + maps.Copy(tagFunctions, cfg.CustomTags) return tagFunctions }