mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-22 17:49:59 +08:00
Use maps.Copy for simpler map handling (#7009)
Some checks failed
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (ubuntu-latest, linux) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
Lint / govulncheck (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled
Tests / test (s390x on IBM Z) (push) Has been cancelled
Tests / goreleaser-check (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, aix) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, darwin) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, dragonfly) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, freebsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, illumos) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, linux) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, netbsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, openbsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, solaris) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, windows) (push) Has been cancelled
Some checks failed
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (ubuntu-latest, linux) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
Lint / govulncheck (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled
Tests / test (s390x on IBM Z) (push) Has been cancelled
Tests / goreleaser-check (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, aix) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, darwin) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, dragonfly) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, freebsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, illumos) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, linux) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, netbsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, openbsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, solaris) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, windows) (push) Has been cancelled
Signed-off-by: eveneast <qcqs@foxmail.com>
This commit is contained in:
@ -19,6 +19,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -335,9 +336,7 @@ func TestAdminHandlerBuiltinRouteErrors(t *testing.T) {
|
|||||||
|
|
||||||
func testGetMetricValue(labels map[string]string) float64 {
|
func testGetMetricValue(labels map[string]string) float64 {
|
||||||
promLabels := prometheus.Labels{}
|
promLabels := prometheus.Labels{}
|
||||||
for k, v := range labels {
|
maps.Copy(promLabels, labels)
|
||||||
promLabels[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
metric, err := adminMetrics.requestErrors.GetMetricWith(promLabels)
|
metric, err := adminMetrics.requestErrors.GetMetricWith(promLabels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -377,9 +376,7 @@ func (m *mockModule) CaddyModule() ModuleInfo {
|
|||||||
|
|
||||||
func TestNewAdminHandlerRouterRegistration(t *testing.T) {
|
func TestNewAdminHandlerRouterRegistration(t *testing.T) {
|
||||||
originalModules := make(map[string]ModuleInfo)
|
originalModules := make(map[string]ModuleInfo)
|
||||||
for k, v := range modules {
|
maps.Copy(originalModules, modules)
|
||||||
originalModules[k] = v
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modules = originalModules
|
modules = originalModules
|
||||||
}()
|
}()
|
||||||
@ -479,9 +476,7 @@ func TestAdminRouterProvisioning(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
originalModules := make(map[string]ModuleInfo)
|
originalModules := make(map[string]ModuleInfo)
|
||||||
for k, v := range modules {
|
maps.Copy(originalModules, modules)
|
||||||
originalModules[k] = v
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modules = originalModules
|
modules = originalModules
|
||||||
}()
|
}()
|
||||||
@ -774,9 +769,7 @@ func (m *mockIssuerModule) CaddyModule() ModuleInfo {
|
|||||||
|
|
||||||
func TestManageIdentity(t *testing.T) {
|
func TestManageIdentity(t *testing.T) {
|
||||||
originalModules := make(map[string]ModuleInfo)
|
originalModules := make(map[string]ModuleInfo)
|
||||||
for k, v := range modules {
|
maps.Copy(originalModules, modules)
|
||||||
originalModules[k] = v
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modules = originalModules
|
modules = originalModules
|
||||||
}()
|
}()
|
||||||
|
@ -16,6 +16,7 @@ package httpcaddyfile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"maps"
|
||||||
"net"
|
"net"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
@ -365,9 +366,7 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
|
|||||||
// copy existing matcher definitions so we can augment
|
// copy existing matcher definitions so we can augment
|
||||||
// new ones that are defined only in this scope
|
// new ones that are defined only in this scope
|
||||||
matcherDefs := make(map[string]caddy.ModuleMap, len(h.matcherDefs))
|
matcherDefs := make(map[string]caddy.ModuleMap, len(h.matcherDefs))
|
||||||
for key, val := range h.matcherDefs {
|
maps.Copy(matcherDefs, h.matcherDefs)
|
||||||
matcherDefs[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
// find and extract any embedded matcher definitions in this scope
|
// find and extract any embedded matcher definitions in this scope
|
||||||
for i := 0; i < len(segments); i++ {
|
for i := 0; i < len(segments); i++ {
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -703,9 +704,7 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io
|
|||||||
if body != nil {
|
if body != nil {
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
for k, v := range headers {
|
maps.Copy(req.Header, headers)
|
||||||
req.Header[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
// make an HTTP client that dials our network type, since admin
|
// make an HTTP client that dials our network type, since admin
|
||||||
// endpoints aren't always TCP, which is what the default transport
|
// endpoints aren't always TCP, which is what the default transport
|
||||||
|
Reference in New Issue
Block a user