Skip to content

Commit e3e16ee

Browse files
author
Vishal Rana
committed
Merge pull request #40 from labstack/develop
Nested groups
2 parents a956a03 + ff75c9c commit e3e16ee

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

echo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func New() (e *Echo) {
147147
// the parent. Passing middleware overrides parent middleware.
148148
func (e *Echo) Group(pfx string, m ...Middleware) *Echo {
149149
g := *e
150-
g.prefix = pfx
150+
g.prefix = g.prefix + pfx
151151
if len(m) > 0 {
152152
g.middleware = nil
153153
g.Use(m...)

echo_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ func TestEchoGroup(t *testing.T) {
218218
if b.String() != "3" {
219219
t.Errorf("should execute middleware 3, executed %s", b.String())
220220
}
221+
222+
// Nested group
223+
g3 := e.Group("/group3")
224+
g4 := g3.Group("/group4")
225+
g4.Get("/home", func(c *Context) {
226+
c.NoContent(http.StatusOK)
227+
})
228+
w = httptest.NewRecorder()
229+
r, _ = http.NewRequest(GET, "/group3/group4/home", nil)
230+
e.ServeHTTP(w, r)
231+
if w.Code != 200 {
232+
t.Errorf("status code should be 200, found %d", w.Code)
233+
}
221234
}
222235

223236
func TestEchoMethod(t *testing.T) {

0 commit comments

Comments
 (0)