2015-05-23 05:26:52 +02:00
|
|
|
package echo
|
|
|
|
|
|
|
|
type (
|
|
|
|
Group struct {
|
2016-02-15 18:11:29 +02:00
|
|
|
prefix string
|
|
|
|
middleware []Middleware
|
|
|
|
echo *Echo
|
2015-05-23 05:26:52 +02:00
|
|
|
}
|
|
|
|
)
|
2015-05-23 06:24:35 +02:00
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Use(middleware ...interface{}) {
|
|
|
|
for _, m := range middleware {
|
|
|
|
g.middleware = append(g.middleware, wrapMiddleware(m))
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Connect(path string, handler interface{}) {
|
|
|
|
g.add(CONNECT, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Delete(path string, handler interface{}) {
|
|
|
|
g.add(DELETE, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Get(path string, handler interface{}) {
|
|
|
|
g.add(GET, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Head(path string, handler interface{}) {
|
|
|
|
g.add(HEAD, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Options(path string, handler interface{}) {
|
|
|
|
g.add(OPTIONS, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Patch(path string, handler interface{}) {
|
|
|
|
g.add(PATCH, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Post(path string, handler interface{}) {
|
|
|
|
g.add(POST, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Put(path string, handler interface{}) {
|
|
|
|
g.add(PUT, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Trace(path string, handler interface{}) {
|
|
|
|
g.add(TRACE, path, handler)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) Group(prefix string, middleware ...interface{}) *Group {
|
|
|
|
return g.echo.Group(prefix, middleware...)
|
2015-05-27 23:07:52 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
func (g *Group) add(method, path string, handler interface{}) {
|
|
|
|
path = g.prefix + path
|
|
|
|
h := wrapHandler(handler)
|
|
|
|
name := handlerName(handler)
|
|
|
|
g.echo.router.Add(method, path, HandlerFunc(func(c Context) error {
|
|
|
|
for i := len(g.middleware) - 1; i >= 0; i-- {
|
|
|
|
h = g.middleware[i].Handle(h)
|
|
|
|
}
|
|
|
|
return h.Handle(c)
|
|
|
|
}), g.echo)
|
|
|
|
r := Route{
|
|
|
|
Method: method,
|
|
|
|
Path: path,
|
|
|
|
Handler: name,
|
|
|
|
}
|
|
|
|
g.echo.router.routes = append(g.echo.router.routes, r)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|