Skip to content

Commit 86281a4

Browse files
author
AnikHasibul
committed
👌 IMPROVE: Automatically add router groups to parent router
1 parent d483976 commit 86281a4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

‎router.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,15 @@ func New() *Router {
158158
// Group returns a new grouped Router.
159159
// Path auto-correction, including trailing slashes, is enabled by default.
160160
func (r *Router) Group(path string) *Router {
161-
return &Router{
161+
g := &Router{
162162
beginPath: path,
163163
RedirectTrailingSlash: true,
164164
RedirectFixedPath: true,
165165
HandleMethodNotAllowed: true,
166166
HandleOPTIONS: true,
167167
}
168+
r.NotFound = g.Handler
169+
return g
168170
}
169171

170172
// GET is a shortcut for router.Handle("GET", path, handle)

‎router_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ func TestRouterChaining(t *testing.T) {
312312
func TestRouterGroup(t *testing.T) {
313313
r1 := New()
314314
r2 := r1.Group("/boo")
315-
r1.NotFound = r2.Handler
316315
fooHit := false
317316
r1.POST("/foo", func(ctx *fasthttp.RequestCtx) {
318317
fooHit = true

0 commit comments

Comments
 (0)