Skip to content

Commit 23a5dc5

Browse files
authored
refactor: use maps.Copy to simplify the code (#627)
1 parent 32942cc commit 23a5dc5

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

log.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"log"
8+
"maps"
89
"os"
910
"reflect"
1011
"slices"
@@ -21,22 +22,16 @@ type LogFields map[string]interface{}
2122
func (l LogFields) Add(newFields LogFields) LogFields {
2223
resultFields := make(LogFields, len(l)+len(newFields))
2324

24-
for field, value := range l {
25-
resultFields[field] = value
26-
}
27-
for field, value := range newFields {
28-
resultFields[field] = value
29-
}
25+
maps.Copy(resultFields, l)
26+
maps.Copy(resultFields, newFields)
3027

3128
return resultFields
3229
}
3330

3431
// Copy copies the LogFields.
3532
func (l LogFields) Copy() LogFields {
3633
cpy := make(LogFields, len(l))
37-
for k, v := range l {
38-
cpy[k] = v
39-
}
34+
maps.Copy(cpy, l)
4035

4136
return cpy
4237
}

0 commit comments

Comments
 (0)