Browse Source

bug fixed for second group

tags/v0.5.5
Lunny Xiao 1 year ago
parent
commit
c29aecfb00
Signed by: lunny <xiaolunwen@gmail.com> GPG Key ID: C3B7C91B632F738A
3 changed files with 43 additions and 2 deletions
  1. +1
    -1
      group.go
  2. +41
    -0
      handler_test.go
  3. +1
    -1
      tan.go

+ 1
- 1
group.go View File

@@ -85,7 +85,7 @@ func (g *Group) Route(methods interface{}, url string, c interface{}, middleware
func (g *Group) Group(p string, o interface{}) {
gr := getGroup(o)
for _, gchild := range gr.routers {
g.Route(gchild.methods, joinRoute(p, gchild.url), gchild.c, gchild.handlers...)
g.Route(gchild.methods, joinRoute(p, gchild.url), gchild.c, append(gr.handlers, gchild.handlers...)...)
}
}



+ 41
- 0
handler_test.go View File

@@ -0,0 +1,41 @@
package tango

import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)

func TestGroupGroup(t *testing.T) {
var a int
tg := Classic()
tg.Group("/api", func(api *Group) {
api.Group("/v1", func(v1 *Group) {
v1.Use(HandlerFunc(func(ctx *Context) {
a = 1
ctx.Next()
}))

v1.Get("/", func(ctx *Context) {
fmt.Println("context")
})

})
})

buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff

req, err := http.NewRequest("GET", "http://localhost:8000/api/v1", nil)
if err != nil {
t.Error(err)
}
tg.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
expect(t, buff.String(), "")
expect(t, 1, a)

}

+ 1
- 1
tan.go View File

@@ -14,7 +14,7 @@ import (

// Version returns tango's version
func Version() string {
return "0.5.5.0104"
return "0.5.5.0412"
}

// Tango describes tango object


Loading…
Cancel
Save