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-16 03:12:15 +02:00
|
|
|
func (g *Group) Connect(path string, h Handler) {
|
|
|
|
g.add(CONNECT, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Delete(path string, h Handler) {
|
|
|
|
g.add(DELETE, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Get(path string, h Handler) {
|
|
|
|
g.add(GET, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Head(path string, h Handler) {
|
|
|
|
g.add(HEAD, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Options(path string, h Handler) {
|
|
|
|
g.add(OPTIONS, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Patch(path string, h Handler) {
|
|
|
|
g.add(PATCH, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Post(path string, h Handler) {
|
|
|
|
g.add(POST, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Put(path string, h Handler) {
|
|
|
|
g.add(PUT, path, h)
|
2015-05-23 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 03:12:15 +02:00
|
|
|
func (g *Group) Trace(path string, h Handler) {
|
|
|
|
g.add(TRACE, path, h)
|
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-16 03:12:15 +02:00
|
|
|
func (g *Group) add(method, path string, h Handler) {
|
2016-02-15 18:11:29 +02:00
|
|
|
path = g.prefix + path
|
2016-02-16 03:12:15 +02:00
|
|
|
name := handlerName(h)
|
2016-02-15 18:11:29 +02:00
|
|
|
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
|
|
|
}
|