aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/ip_matchers.go
diff options
context:
space:
mode:
authorKévin Dunglas <[email protected]>2024-09-13 19:16:37 +0200
committerGitHub <[email protected]>2024-09-13 11:16:37 -0600
commitf4bf4e0097853438eb69c573bbaa0581e9b9c02d (patch)
tree2c01222faa34d3c95072094a2f80c41b1563c19e /modules/caddyhttp/ip_matchers.go
parent21f9c20a04ec5c2ac430daa8e4ba8fbdef67f773 (diff)
downloadcaddy-f4bf4e0097853438eb69c573bbaa0581e9b9c02d.tar.gz
caddy-f4bf4e0097853438eb69c573bbaa0581e9b9c02d.zip
perf: use zap's Check() to prevent useless allocs (#6560)
* perf: use zap's Check() to prevent useless allocs * fix * fix * fix * fix * restore previous replacer behavior * fix linter
Diffstat (limited to 'modules/caddyhttp/ip_matchers.go')
-rw-r--r--modules/caddyhttp/ip_matchers.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/caddyhttp/ip_matchers.go b/modules/caddyhttp/ip_matchers.go
index 2e735cb69..99eb39dff 100644
--- a/modules/caddyhttp/ip_matchers.go
+++ b/modules/caddyhttp/ip_matchers.go
@@ -26,6 +26,7 @@ import (
"github.com/google/cel-go/cel"
"github.com/google/cel-go/common/types/ref"
"go.uber.org/zap"
+ "go.uber.org/zap/zapcore"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -150,12 +151,17 @@ func (m MatchRemoteIP) Match(r *http.Request) bool {
address := r.RemoteAddr
clientIP, zoneID, err := parseIPZoneFromString(address)
if err != nil {
- m.logger.Error("getting remote IP", zap.Error(err))
+ if c := m.logger.Check(zapcore.ErrorLevel, "getting remote "); c != nil {
+ c.Write(zap.Error(err))
+ }
+
return false
}
matches, zoneFilter := matchIPByCidrZones(clientIP, zoneID, m.cidrs, m.zones)
if !matches && !zoneFilter {
- m.logger.Debug("zone ID from remote IP did not match", zap.String("zone", zoneID))
+ if c := m.logger.Check(zapcore.DebugLevel, "zone ID from remote IP did not match"); c != nil {
+ c.Write(zap.String("zone", zoneID))
+ }
}
return matches
}