From f1710ea1b648956eb87e163ec6bace4dcfb40ae4 Mon Sep 17 00:00:00 2001 From: wernerr Date: Fri, 19 Jun 2020 10:54:15 +0200 Subject: [PATCH] fix the unnecessary pass through for routes with groups --- app_test.go | 19 +++++++++++++++++++ group.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app_test.go b/app_test.go index 3c7e06d811..5e3a32d52a 100644 --- a/app_test.go +++ b/app_test.go @@ -525,6 +525,25 @@ func Test_App_Group(t *testing.T) { //utils.AssertEqual(t, "/test/v1/users", resp.Header.Get("Location"), "Location") } +func Test_App_Deep_Group(t *testing.T) { + runThroughCount := 0 + var dummyHandler = func(c *Ctx) { + runThroughCount++ + c.Next() + } + + app := New() + gApi := app.Group("/api", dummyHandler) + gV1 := gApi.Group("/v1", dummyHandler) + gUser := gV1.Group("/user", dummyHandler) + gUser.Get("/authenticate", func(ctx *Ctx) { + runThroughCount++ + ctx.SendStatus(200) + }) + testStatus200(t, app, "/api/v1/user/authenticate", "GET") + utils.AssertEqual(t, 4, runThroughCount, "Loop count") +} + func Test_App_Listen(t *testing.T) { app := New(&Settings{ DisableStartupMessage: true, diff --git a/group.go b/group.go index a264784d00..124272e3ec 100644 --- a/group.go +++ b/group.go @@ -108,5 +108,5 @@ func (grp *Group) Group(prefix string, handlers ...Handler) *Group { if len(handlers) > 0 { grp.app.register("USE", prefix, handlers...) } - return grp.app.Group(prefix, handlers...) + return grp.app.Group(prefix) }