♻️ refactor: use maps.Copy to simplify code (#3490)

This commit is contained in:
Oleksandr Redko 2025-05-28 13:49:33 +03:00 committed by GitHub
parent 557095b094
commit 956205311b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 12 deletions

View File

@ -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 {

View File

@ -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.

View File

@ -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
}