mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
parent
796df515f3
commit
891d8519d7
15
echo.go
15
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
2
group.go
2
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.
|
||||
|
Loading…
Reference in New Issue
Block a user