1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-10-30 15:03:18 -07:00
parent 796df515f3
commit 891d8519d7
2 changed files with 13 additions and 4 deletions

15
echo.go
View File

@ -121,6 +121,11 @@ type (
// Map defines a generic map of type `map[string]interface{}`.
Map map[string]interface{}
// i is the interface for Echo and Group.
i interface {
GET(string, HandlerFunc, ...MiddlewareFunc)
}
)
// HTTP methods
@ -384,14 +389,18 @@ func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middlew
// Static registers a new route with path prefix to serve static files from the
// provided root directory.
func (e *Echo) Static(prefix, root string) {
static(e, prefix, root)
}
func static(i i, prefix, root string) {
h := func(c Context) error {
return c.File(path.Join(root, c.Param("*")))
}
e.GET(prefix, h)
i.GET(prefix, h)
if prefix == "/" {
e.GET(prefix+"*", h)
i.GET(prefix+"*", h)
} else {
e.GET(prefix+"/*", h)
i.GET(prefix+"/*", h)
}
}

View File

@ -85,7 +85,7 @@ func (g *Group) Group(prefix string, middleware ...MiddlewareFunc) *Group {
// Static implements `Echo#Static()` for sub-routes within the Group.
func (g *Group) Static(prefix, root string) {
g.echo.Static(g.prefix+prefix, root)
static(g, prefix, root)
}
// File implements `Echo#File()` for sub-routes within the Group.