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-16 03:12:15 +02:00
|
|
|
func (g *Group) Use(m ...Middleware) {
|
|
|
|
g.middleware = append(g.middleware, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Connect(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(CONNECT, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Delete(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(DELETE, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Get(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(GET, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Head(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(HEAD, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Options(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(OPTIONS, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Patch(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(PATCH, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Post(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(POST, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Put(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(PUT, path, h, m...)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) Trace(path string, h Handler, m ...Middleware) {
|
|
|
|
g.add(TRACE, path, h, m...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Group) Any(path string, handler Handler, middleware ...Middleware) {
|
|
|
|
for _, m := range methods {
|
|
|
|
g.add(m, path, handler, middleware...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Group) Match(methods []string, path string, handler Handler, middleware ...Middleware) {
|
|
|
|
for _, m := range methods {
|
|
|
|
g.add(m, path, handler, middleware...)
|
|
|
|
}
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Group(prefix string, m ...Middleware) *Group {
|
|
|
|
return g.echo.Group(prefix, m...)
|
2015-05-27 23:07:52 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:11:02 +02:00
|
|
|
func (g *Group) add(method, path string, handler Handler, middleware ...Middleware) {
|
2016-02-15 18:11:29 +02:00
|
|
|
path = g.prefix + path
|
2016-02-20 18:11:02 +02:00
|
|
|
name := handlerName(handler)
|
|
|
|
middleware = append(g.middleware, middleware...)
|
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
g.echo.router.Add(method, path, HandlerFunc(func(c Context) error {
|
2016-02-20 18:11:02 +02:00
|
|
|
for _, m := range middleware {
|
|
|
|
handler = m.Handle(handler)
|
2016-02-15 18:11:29 +02:00
|
|
|
}
|
2016-02-20 18:11:02 +02:00
|
|
|
return handler.Handle(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
}), 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
|
|
|
}
|