Skip to content

Commit be60b2e

Browse files
authored
Simplify chi.walk with slices.Concat (#1053)
Should perform better too as the initial allocation will be sized to fit both slices unlike before.
1 parent a36a925 commit be60b2e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tree.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"regexp"
11+
"slices"
1112
"sort"
1213
"strconv"
1314
"strings"
@@ -836,9 +837,7 @@ func Walk(r Routes, walkFn WalkFunc) error {
836837

837838
func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error {
838839
for _, route := range r.Routes() {
839-
mws := make([]func(http.Handler) http.Handler, len(parentMw))
840-
copy(mws, parentMw)
841-
mws = append(mws, r.Middlewares()...)
840+
mws := slices.Concat(parentMw, r.Middlewares())
842841

843842
if route.SubRoutes != nil {
844843
if handler, ok := route.Handlers["*"]; ok {

0 commit comments

Comments
 (0)