From 51a1ef432ca47a6caf94e990c5141cf91bf5b4e3 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 24 Sep 2015 14:14:01 -0700 Subject: [PATCH] Fixed #222 Signed-off-by: Vishal Rana --- recipes/file-upload/server.go | 3 +-- router.go | 29 +++++++++++++++-------------- website/docs/recipes/file-upload.md | 3 +-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/recipes/file-upload/server.go b/recipes/file-upload/server.go index fef5c853..e01c1fb3 100644 --- a/recipes/file-upload/server.go +++ b/recipes/file-upload/server.go @@ -12,8 +12,7 @@ import ( func upload(c *echo.Context) error { req := c.Request() - - // req.ParseMultipartForm(16 << 20) // Max memory 16 MiB + req.ParseMultipartForm(16 << 20) // Max memory 16 MiB // Read form fields name := c.Form("name") diff --git a/router.go b/router.go index 41e5a587..1a4c0603 100644 --- a/router.go +++ b/router.go @@ -285,9 +285,9 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo // Strip trailing slash if r.echo.stripTrailingSlash { - l := len(path) - if path != "/" && path[l-1] == '/' { // Issue #218 - path = path[:l-1] + l := len(path)-1 + if path != "/" && path[l] == '/' { // Issue #218 + path = path[:l] } } @@ -303,13 +303,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo // Search order static > param > match-any for { if search == "" { - if cn.handler != nil { - // Found - ctx.pnames = cn.pnames - h = cn.handler - e = cn.echo - } - return + goto Found } pl := 0 // Prefix length @@ -348,10 +342,12 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo if cn.handler == nil { // Look up for match-any, might have an empty value for *, e.g. // serving a directory. Issue #207 - cn = cn.findChildWithType(mtype) + if cn = cn.findChildWithType(mtype); cn == nil { + return + } ctx.pvalues[len(cn.pnames)-1] = "" } - continue + goto Found } // Static node @@ -394,13 +390,18 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo if c != nil { cn = c ctx.pvalues[len(cn.pnames)-1] = search - search = "" // End search - continue + goto Found } // Not found return } + +Found: + ctx.pnames = cn.pnames + h = cn.handler + e = cn.echo + return } func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) { diff --git a/website/docs/recipes/file-upload.md b/website/docs/recipes/file-upload.md index a8628ac5..fb84b9c5 100644 --- a/website/docs/recipes/file-upload.md +++ b/website/docs/recipes/file-upload.md @@ -25,8 +25,7 @@ import ( func upload(c *echo.Context) error { req := c.Request() - - // req.ParseMultipartForm(16 << 20) // Max memory 16 MiB + req.ParseMultipartForm(16 << 20) // Max memory 16 MiB // Read form fields name := c.Form("name")