Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions modules/caddyhttp/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/caddyserver/caddy/v2"
)
Expand Down Expand Up @@ -110,14 +111,16 @@ func (r Route) Empty() bool {
}

func (r Route) String() string {
handlersRaw := "["
var handlersRaw strings.Builder
handlersRaw.WriteByte('[')
for _, hr := range r.HandlersRaw {
handlersRaw += " " + string(hr)
handlersRaw.WriteByte(' ')
handlersRaw.WriteString(string(hr))
}
handlersRaw += "]"
handlersRaw.WriteByte(']')

return fmt.Sprintf(`{Group:"%s" MatcherSetsRaw:%s HandlersRaw:%s Terminal:%t}`,
r.Group, r.MatcherSetsRaw, handlersRaw, r.Terminal)
r.Group, r.MatcherSetsRaw, handlersRaw.String(), r.Terminal)
}

// Provision sets up both the matchers and handlers in the route.
Expand Down Expand Up @@ -440,13 +443,15 @@ func (ms *MatcherSets) FromInterface(matcherSets any) error {

// TODO: Is this used?
func (ms MatcherSets) String() string {
result := "["
var result strings.Builder
result.WriteByte('[')
for _, matcherSet := range ms {
for _, matcher := range matcherSet {
result += fmt.Sprintf(" %#v", matcher)
result.WriteString(fmt.Sprintf(" %#v", matcher))
}
}
return result + " ]"
result.WriteByte(']')
return result.String()
}

var routeGroupCtxKey = caddy.CtxKey("route_group")
10 changes: 5 additions & 5 deletions modules/logging/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field {
}

func (m IPMaskFilter) mask(s string) string {
output := ""
parts := make([]string, 0)
for value := range strings.SplitSeq(s, ",") {
value = strings.TrimSpace(value)
host, port, err := net.SplitHostPort(value)
Expand All @@ -264,7 +264,7 @@ func (m IPMaskFilter) mask(s string) string {
}
ipAddr := net.ParseIP(host)
if ipAddr == nil {
output += value + ", "
parts = append(parts, value)
continue
}
mask := m.v4Mask
Expand All @@ -273,13 +273,13 @@ func (m IPMaskFilter) mask(s string) string {
}
masked := ipAddr.Mask(mask)
if port == "" {
output += masked.String() + ", "
parts = append(parts, masked.String())
continue
}

output += net.JoinHostPort(masked.String(), port) + ", "
parts = append(parts, net.JoinHostPort(masked.String(), port))
}
return strings.TrimSuffix(output, ", ")
return strings.Join(parts, ", ")
}

type filterAction string
Expand Down
Loading