mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
♻️ refactor: use maps.Copy to simplify code (#3490)
This commit is contained in:
parent
557095b094
commit
956205311b
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user