From d0f44c90bac4781ff295b52a9ae893c1c1da9a79 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Fri, 3 Apr 2015 15:40:36 -0700 Subject: [PATCH] Minor changes in router Signed-off-by: Vishal Rana --- context.go | 1 + echo.go | 6 ++++-- router.go | 5 ++--- router_test.go | 10 +++++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/context.go b/context.go index 889f831e..b0ec4216 100644 --- a/context.go +++ b/context.go @@ -38,6 +38,7 @@ func (c *Context) Bind(i interface{}) (err error) { if err = dec.Decode(i); err != nil { err = ErrBindJSON } + } else if strings.HasPrefix(ct, MIMEForm) { } else { err = ErrUnsupportedContentType } diff --git a/echo.go b/echo.go index 9899bd8b..f7a771e2 100644 --- a/echo.go +++ b/echo.go @@ -35,8 +35,10 @@ const ( MethodPUT = "PUT" MethodTRACE = "TRACE" - MIMEJSON = "application/json" - MIMEText = "text/plain" + MIMEJSON = "application/json" + MIMEText = "text/plain" + MIMEForm = "application/x-www-form-urlencoded" + MIMEMultipartForm = "multipart/form-data" HeaderAccept = "Accept" HeaderContentDisposition = "Content-Disposition" diff --git a/router.go b/router.go index bc7c0666..424f889d 100644 --- a/router.go +++ b/router.go @@ -167,6 +167,7 @@ func (r *router) Find(method, path string) (h HandlerFunc, c *Context, echo *Ech for { if search == "" || search == cn.prefix { + // Found h = cn.handler echo = cn.echo return @@ -210,10 +211,8 @@ func (r *router) Find(method, path string) (h HandlerFunc, c *Context, echo *Ech } cn = e continue - } else { - // Not found - return } + return } } diff --git a/router_test.go b/router_test.go index 82bf3a3a..dfb6541c 100644 --- a/router_test.go +++ b/router_test.go @@ -57,9 +57,17 @@ func TestRouterMicroParam(t *testing.T) { } } +func TestRouterConflict(t *testing.T) { + r := New().Router + r.Add("GET", "/users/new", func(*Context) {}, nil) + r.Add("GET", "/users/wen", func(*Context) {}, nil) + r.Add("GET", "/users/:id", func(*Context) {}, nil) + r.trees["GET"].printTree("", true) +} + func (n *node) printTree(pfx string, tail bool) { p := prefix(tail, pfx, "└── ", "├── ") - fmt.Printf("%s%s has=%d, h=%v, eid=%d\n", p, n.prefix, n.has, n.handler, n.echo) + fmt.Printf("%s%s has=%d, h=%v, echo=%d\n", p, n.prefix, n.has, n.handler, n.echo) nodes := n.edges l := len(nodes)