diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index b0fe3c08e..3432de2b3 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -2,6 +2,7 @@ package configuration import ( "bytes" + "maps" "net/http" "reflect" "strings" @@ -507,9 +508,7 @@ func copyConfig(config Configuration) *Configuration { configCopy.Log = config.Log configCopy.Catalog = config.Catalog configCopy.Log.Fields = make(map[string]interface{}, len(config.Log.Fields)) - for k, v := range config.Log.Fields { - configCopy.Log.Fields[k] = v - } + maps.Copy(configCopy.Log.Fields, config.Log.Fields) configCopy.Storage = Storage{config.Storage.Type(): Parameters{}} for k, v := range config.Storage.Parameters() { @@ -528,9 +527,7 @@ func copyConfig(config Configuration) *Configuration { configCopy.Notifications.Endpoints = append(configCopy.Notifications.Endpoints, config.Notifications.Endpoints...) configCopy.HTTP.Headers = make(http.Header) - for k, v := range config.HTTP.Headers { - configCopy.HTTP.Headers[k] = v - } + maps.Copy(configCopy.HTTP.Headers, config.HTTP.Headers) configCopy.HTTP.TLS.ClientCAs = make([]string, 0, len(config.HTTP.TLS.ClientCAs)) configCopy.HTTP.TLS.ClientCAs = append(configCopy.HTTP.TLS.ClientCAs, config.HTTP.TLS.ClientCAs...) configCopy.HTTP.TLS.ClientAuth = config.HTTP.TLS.ClientAuth diff --git a/internal/client/auth/session_test.go b/internal/client/auth/session_test.go index 6e8235240..3f49cfbb6 100644 --- a/internal/client/auth/session_test.go +++ b/internal/client/auth/session_test.go @@ -3,6 +3,7 @@ package auth import ( "encoding/base64" "fmt" + "maps" "net/http" "net/http/httptest" "net/url" @@ -38,9 +39,7 @@ func (w *testAuthenticationWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Re auth := r.Header.Get("Authorization") if auth == "" || !w.authCheck(auth) { h := rw.Header() - for k, values := range w.headers { - h[k] = values - } + maps.Copy(h, w.headers) rw.WriteHeader(http.StatusUnauthorized) return } diff --git a/internal/dcontext/context.go b/internal/dcontext/context.go index fe8379800..b9a180d90 100644 --- a/internal/dcontext/context.go +++ b/internal/dcontext/context.go @@ -2,6 +2,7 @@ package dcontext import ( "context" + "maps" "sync" "github.com/google/uuid" @@ -52,9 +53,7 @@ type stringMapContext struct { // supports string keys. func WithValues(ctx context.Context, m map[string]interface{}) context.Context { mo := make(map[string]interface{}, len(m)) // make our own copy. - for k, v := range m { - mo[k] = v - } + maps.Copy(mo, m) return stringMapContext{ Context: ctx, diff --git a/notifications/endpoint.go b/notifications/endpoint.go index f67e8cfe7..ad2227517 100644 --- a/notifications/endpoint.go +++ b/notifications/endpoint.go @@ -1,6 +1,7 @@ package notifications import ( + "maps" "net/http" "time" @@ -92,7 +93,5 @@ func (e *Endpoint) ReadMetrics(em *EndpointMetrics) { *em = e.metrics.EndpointMetrics // Map still need to copied in a threadsafe manner. em.Statuses = make(map[string]int) - for k, v := range e.metrics.Statuses { - em.Statuses[k] = v - } + maps.Copy(em.Statuses, e.metrics.Statuses) } diff --git a/testutil/handler.go b/testutil/handler.go index 96aa0fe7a..d86296050 100644 --- a/testutil/handler.go +++ b/testutil/handler.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "maps" "net/http" "net/url" "sort" @@ -137,9 +138,7 @@ func (app *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { app.responseMap[request.String()] = responses[1:] responseHeader := w.Header() - for k, v := range response.Headers { - responseHeader[k] = v - } + maps.Copy(responseHeader, response.Headers) w.WriteHeader(response.StatusCode)