mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
Getting echo reference from the node
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
5b019c507e
commit
f839210454
5
echo.go
5
echo.go
@ -463,10 +463,7 @@ func (e *Echo) Routes() []Route {
|
||||
// ServeHTTP implements `http.Handler` interface, which serves HTTP requests.
|
||||
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c := e.pool.Get().(*Context)
|
||||
h, echo := e.router.Find(r.Method, r.URL.Path, c)
|
||||
if echo != nil {
|
||||
e = echo
|
||||
}
|
||||
h, e := e.router.Find(r.Method, r.URL.Path, c)
|
||||
c.reset(r, w, e)
|
||||
|
||||
// Chain middleware with handler in the end
|
||||
|
11
router.go
11
router.go
@ -261,6 +261,7 @@ func (n *node) findHandler(method string) HandlerFunc {
|
||||
|
||||
func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo) {
|
||||
h = notFoundHandler
|
||||
e = r.echo
|
||||
cn := r.tree // Current node as root
|
||||
|
||||
// Strip trailing slash
|
||||
@ -369,17 +370,23 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
|
||||
Found:
|
||||
ctx.pnames = cn.pnames
|
||||
h = cn.findHandler(method)
|
||||
if cn.echo != nil {
|
||||
e = cn.echo
|
||||
}
|
||||
if h == nil {
|
||||
h = methodNotAllowedHandler
|
||||
// Look up for match-any, might have an empty value for *, e.g.
|
||||
// Dig further for match-any, might have an empty value for *, e.g.
|
||||
// serving a directory. Issue #207
|
||||
if cn = cn.findChildWithType(mtype); cn == nil {
|
||||
return
|
||||
}
|
||||
// println("here...")
|
||||
// if cn.echo != nil {
|
||||
// e = cn.echo
|
||||
// }
|
||||
h = cn.findHandler(method)
|
||||
ctx.pvalues[len(cn.pnames)-1] = ""
|
||||
}
|
||||
e = cn.echo
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ code {
|
||||
color: #424242;
|
||||
font-size: .95em;
|
||||
font-family: Source Code Pro, Monaco, Menlo, Consolas, monospace;
|
||||
border: 1px solid #BDBDBD;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #E0E0E0;
|
||||
border-radius: 2px;
|
||||
}
|
||||
a:link {
|
||||
text-decoration: none;
|
||||
|
Loading…
Reference in New Issue
Block a user