Simplify chi.walk with slices.Concat (#1053)

Should perform better too as the initial allocation will be sized to fit
both slices unlike before.
This commit is contained in:
James Raspass 2026-02-19 13:12:24 +00:00 committed by GitHub
parent a36a925a6a
commit be60b2ec57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"regexp"
"slices"
"sort"
"strconv"
"strings"
@ -836,9 +837,7 @@ func Walk(r Routes, walkFn WalkFunc) error {
func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error {
for _, route := range r.Routes() {
mws := make([]func(http.Handler) http.Handler, len(parentMw))
copy(mws, parentMw)
mws = append(mws, r.Middlewares()...)
mws := slices.Concat(parentMw, r.Middlewares())
if route.SubRoutes != nil {
if handler, ok := route.Handlers["*"]; ok {