@marcel91200 / caddy Mirror · read-only / commits / a76d005a
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 23:30 UTC

Use maps.Copy for simpler map handling (#7009)

Signed-off-by: eveneast <qcqs@foxmail.com>

eveneast committed May 14, 2025 at 05:16 UTC a76d005a94ff8ee19fc17f5409b4089c2bfd1a60
3 files changed +9 -18
admin_test.go
+5 -12
@@ -19,6 +19,7 @@ import (
19 "crypto/x509"
20 "encoding/json"
21 "fmt"
22 + "maps"
23 "net/http"
24 "net/http/httptest"
25 "reflect"
@@ -335,9 +336,7 @@ func TestAdminHandlerBuiltinRouteErrors(t *testing.T) {
336
337 func testGetMetricValue(labels map[string]string) float64 {
338 promLabels := prometheus.Labels{}
338 - for k, v := range labels {
339 - promLabels[k] = v
340 - }
339 + maps.Copy(promLabels, labels)
340
341 metric, err := adminMetrics.requestErrors.GetMetricWith(promLabels)
342 if err != nil {
@@ -377,9 +376,7 @@ func (m *mockModule) CaddyModule() ModuleInfo {
376
377 func TestNewAdminHandlerRouterRegistration(t *testing.T) {
378 originalModules := make(map[string]ModuleInfo)
380 - for k, v := range modules {
381 - originalModules[k] = v
382 - }
379 + maps.Copy(originalModules, modules)
380 defer func() {
381 modules = originalModules
382 }()
@@ -479,9 +476,7 @@ func TestAdminRouterProvisioning(t *testing.T) {
476 for _, test := range tests {
477 t.Run(test.name, func(t *testing.T) {
478 originalModules := make(map[string]ModuleInfo)
482 - for k, v := range modules {
483 - originalModules[k] = v
484 - }
479 + maps.Copy(originalModules, modules)
480 defer func() {
481 modules = originalModules
482 }()
@@ -774,9 +769,7 @@ func (m *mockIssuerModule) CaddyModule() ModuleInfo {
769
770 func TestManageIdentity(t *testing.T) {
771 originalModules := make(map[string]ModuleInfo)
777 - for k, v := range modules {
778 - originalModules[k] = v
779 - }
772 + maps.Copy(originalModules, modules)
773 defer func() {
774 modules = originalModules
775 }()
caddyconfig/httpcaddyfile/directives.go
+2 -3
@@ -16,6 +16,7 @@ package httpcaddyfile
16
17 import (
18 "encoding/json"
19 + "maps"
20 "net"
21 "slices"
22 "sort"
@@ -365,9 +366,7 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
366 // copy existing matcher definitions so we can augment
367 // new ones that are defined only in this scope
368 matcherDefs := make(map[string]caddy.ModuleMap, len(h.matcherDefs))
368 - for key, val := range h.matcherDefs {
369 - matcherDefs[key] = val
370 - }
369 + maps.Copy(matcherDefs, h.matcherDefs)
370
371 // find and extract any embedded matcher definitions in this scope
372 for i := 0; i < len(segments); i++ {
cmd/commandfuncs.go
+2 -3
@@ -24,6 +24,7 @@ import (
24 "io"
25 "io/fs"
26 "log"
27 + "maps"
28 "net"
29 "net/http"
30 "os"
@@ -703,9 +704,7 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io
704 if body != nil {
705 req.Header.Set("Content-Type", "application/json")
706 }
706 - for k, v := range headers {
707 - req.Header[k] = v
708 - }
707 + maps.Copy(req.Header, headers)
708
709 // make an HTTP client that dials our network type, since admin
710 // endpoints aren't always TCP, which is what the default transport