mirror of
https://github.com/labstack/echo.git
synced 2025-09-16 09:16:29 +02:00
2
echo.go
2
echo.go
@@ -375,7 +375,7 @@ func (e *Echo) Static(path, dir string) {
|
|||||||
// ServeDir serves files from a directory.
|
// ServeDir serves files from a directory.
|
||||||
func (e *Echo) ServeDir(path, dir string) {
|
func (e *Echo) ServeDir(path, dir string) {
|
||||||
e.Get(path+"*", func(c *Context) error {
|
e.Get(path+"*", func(c *Context) error {
|
||||||
return serveFile(dir, c.P(0), c) // Param `_name`
|
return serveFile(dir, c.P(0), c) // Param `_*`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ func (r *Router) Add(method, path string, h HandlerFunc, e *Echo) {
|
|||||||
r.insert(method, path[:i], nil, ptype, pnames, e)
|
r.insert(method, path[:i], nil, ptype, pnames, e)
|
||||||
} else if path[i] == '*' {
|
} else if path[i] == '*' {
|
||||||
r.insert(method, path[:i], nil, stype, nil, e)
|
r.insert(method, path[:i], nil, stype, nil, e)
|
||||||
pnames = append(pnames, "_name")
|
pnames = append(pnames, "_*")
|
||||||
r.insert(method, path[:i+1], h, mtype, pnames, e)
|
r.insert(method, path[:i+1], h, mtype, pnames, e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -351,7 +351,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
|
|||||||
// Look up for match-any, might have an empty value for *, e.g.
|
// Look up for match-any, might have an empty value for *, e.g.
|
||||||
// serving a directory. Issue #207
|
// serving a directory. Issue #207
|
||||||
cn = cn.findChildWithType(mtype)
|
cn = cn.findChildWithType(mtype)
|
||||||
ctx.pvalues[len(ctx.pvalues)-1] = ""
|
ctx.pvalues[len(cn.pnames)-1] = ""
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -395,7 +395,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
|
|||||||
c = cn.findChildWithType(mtype)
|
c = cn.findChildWithType(mtype)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
cn = c
|
cn = c
|
||||||
ctx.pvalues[len(ctx.pvalues)-1] = search
|
ctx.pvalues[len(cn.pnames)-1] = search
|
||||||
search = "" // End search
|
search = "" // End search
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@@ -499,7 +499,7 @@ func TestRouterPriority(t *testing.T) {
|
|||||||
if assert.NotNil(t, h) {
|
if assert.NotNil(t, h) {
|
||||||
h(c)
|
h(c)
|
||||||
assert.Equal(t, 7, c.Get("g"))
|
assert.Equal(t, 7, c.Get("g"))
|
||||||
assert.Equal(t, "joe/books", c.Param("_name"))
|
assert.Equal(t, "joe/books", c.Param("_*"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user