Skip to content

Commit

Permalink
Feat/remove tree middleware (#45)
Browse files Browse the repository at this point in the history
* feat: remove middlewares from tree

* feat: remove middlewares from tree

* feat: remove middlewares from tree
  • Loading branch information
tigerwill90 authored Oct 16, 2024
1 parent 775d517 commit 3bea8fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion fox.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (fox *Router) ClientIPStrategyEnabled() bool {
// This API is EXPERIMENTAL and is likely to change in future release.
func (fox *Router) NewTree() *Tree {
tree := new(Tree)
tree.mws = fox.mws
tree.fox = fox

// Pre instantiate nodes for common http verb
Expand Down
7 changes: 7 additions & 0 deletions fox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,13 @@ func TestRouteMiddleware(t *testing.T) {
assert.True(t, c2)
}

func TestMiddlewareLength(t *testing.T) {
f := New(DefaultOptions())
r := f.MustHandle(http.MethodGet, "/", emptyHandler, WithMiddleware(Recovery(), Logger()))
assert.Len(t, f.mws, 2)
assert.Len(t, r.mws, 4)
}

func TestWithNotFoundHandler(t *testing.T) {
notFound := func(c Context) {
_ = c.String(http.StatusNotFound, "NOT FOUND\n")
Expand Down
3 changes: 1 addition & 2 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Tree struct {
ctx sync.Pool
nodes atomic.Pointer[[]*node]
fox *Router
mws []middleware
sync.Mutex
maxParams atomic.Uint32
maxDepth atomic.Uint32
Expand Down Expand Up @@ -954,7 +953,7 @@ func (t *Tree) newRoute(path string, handler HandlerFunc, opts ...PathOption) *R
ipStrategy: t.fox.ipStrategy,
hbase: handler,
path: path,
mws: t.mws,
mws: t.fox.mws,
redirectTrailingSlash: t.fox.redirectTrailingSlash,
ignoreTrailingSlash: t.fox.ignoreTrailingSlash,
}
Expand Down

0 comments on commit 3bea8fb

Please sign in to comment.