diff --git a/echo.go b/echo.go index 0f0c8837..6ee2da60 100644 --- a/echo.go +++ b/echo.go @@ -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) } } diff --git a/group.go b/group.go index 5c6188b1..9767bb19 100644 --- a/group.go +++ b/group.go @@ -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.