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:
parent
a36a925a6a
commit
be60b2ec57
1 changed files with 2 additions and 3 deletions
5
tree.go
5
tree.go
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue