mirror of
https://github.com/labstack/echo.git
synced 2025-02-15 13:53:06 +02:00
parent
50fed083a7
commit
e918eacd9d
16
group.go
16
group.go
@ -1,5 +1,7 @@
|
|||||||
package echo
|
package echo
|
||||||
|
|
||||||
|
import "path"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Group is a set of sub-routes for a specified route. It can be used for inner
|
// Group is a set of sub-routes for a specified route. It can be used for inner
|
||||||
// routes that share a common middlware or functionality that should be separate
|
// routes that share a common middlware or functionality that should be separate
|
||||||
@ -135,18 +137,22 @@ func (g *Group) Group(prefix string, middleware ...MiddlewareFunc) *Group {
|
|||||||
|
|
||||||
// Static implements `Echo#Static()` for sub-routes within the Group.
|
// Static implements `Echo#Static()` for sub-routes within the Group.
|
||||||
func (g *Group) Static(prefix, root string) {
|
func (g *Group) Static(prefix, root string) {
|
||||||
g.echo.Static(g.prefix+prefix, root)
|
g.GET(g.prefix+prefix+"*", func(c Context) error {
|
||||||
|
return c.File(path.Join(root, c.P(0)))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// File implements `Echo#File()` for sub-routes within the Group.
|
// File implements `Echo#File()` for sub-routes within the Group.
|
||||||
func (g *Group) File(path, file string) {
|
func (g *Group) File(path, file string) {
|
||||||
g.echo.File(g.prefix+path, file)
|
g.GET(g.prefix+path, func(c Context) error {
|
||||||
|
return c.File(file)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) add(method, path string, handler HandlerFunc, middleware ...MiddlewareFunc) {
|
func (g *Group) add(method, path string, handler HandlerFunc, middleware ...MiddlewareFunc) {
|
||||||
// Combine into a new slice, to avoid accidentally passing the same
|
// Combine into a new slice to avoid accidentally passing the same slice for
|
||||||
// slice for multiple routes, which would lead to later add() calls overwriting
|
// multiple routes, which would lead to later add() calls overwriting the
|
||||||
// the middleware from earlier calls
|
// middleware from earlier calls.
|
||||||
m := []MiddlewareFunc{}
|
m := []MiddlewareFunc{}
|
||||||
m = append(m, g.middleware...)
|
m = append(m, g.middleware...)
|
||||||
m = append(m, middleware...)
|
m = append(m, middleware...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user