Skip to content

Commit 9562053

Browse files
authored
♻️ refactor: use maps.Copy to simplify code (#3490)
1 parent 557095b commit 9562053

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

binder/mapping.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package binder
33
import (
44
"errors"
55
"fmt"
6+
"maps"
67
"mime/multipart"
78
"reflect"
89
"strings"
@@ -115,9 +116,7 @@ func parseToMap(ptr any, data map[string][]string) error {
115116
return ErrMapNotConvertable
116117
}
117118

118-
for k, v := range data {
119-
newMap[k] = v
120-
}
119+
maps.Copy(newMap, data)
121120
case reflect.String, reflect.Interface:
122121
newMap, ok := ptr.(map[string]string)
123122
if !ok {

client/request.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"io"
88
"iter"
9+
"maps"
910
"path/filepath"
1011
"reflect"
1112
"slices"
@@ -748,9 +749,7 @@ func (c Cookie) SetCookie(key, val string) {
748749

749750
// SetCookies sets multiple cookies from a map.
750751
func (c Cookie) SetCookies(m map[string]string) {
751-
for k, v := range m {
752-
c[k] = v
753-
}
752+
maps.Copy(c, m)
754753
}
755754

756755
// SetCookiesWithStruct sets cookies from a struct.
@@ -800,9 +799,7 @@ func (p PathParam) SetParam(key, val string) {
800799

801800
// SetParams sets multiple path parameters from a map.
802801
func (p PathParam) SetParams(m map[string]string) {
803-
for k, v := range m {
804-
p[k] = v
805-
}
802+
maps.Copy(p, m)
806803
}
807804

808805
// SetParamsWithStruct sets multiple path parameters from a struct.

middleware/logger/tags.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package logger
22

33
import (
44
"fmt"
5+
"maps"
56
"strings"
67

78
"github.com/gofiber/fiber/v3"
@@ -204,9 +205,7 @@ func createTagMap(cfg *Config) map[string]LogFunc {
204205
},
205206
}
206207
// merge with custom tags from user
207-
for k, v := range cfg.CustomTags {
208-
tagFunctions[k] = v
209-
}
208+
maps.Copy(tagFunctions, cfg.CustomTags)
210209

211210
return tagFunctions
212211
}

0 commit comments

Comments
 (0)