forked from rimba47prayoga/gorim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
30 lines (25 loc) · 941 Bytes
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package gorim
import "github.com/labstack/echo/v4"
// Group is a custom group that extends Echo's Group
type Group struct {
EchoGroup *echo.Group // Embed the Echo Group
}
func (g *Group) Group(prefix string, middleware ...echo.MiddlewareFunc) *Group {
echoGroup := g.EchoGroup.Group(prefix, middleware...)
return &Group{
EchoGroup: echoGroup,
}
}
func (g *Group) Use(middleware ...echo.MiddlewareFunc) {
g.EchoGroup.Use(middleware...)
}
// Add implements `Echo#Add()` for sub-routes within the Group.
func (g *Group) Add(method string, path string, handler HandlerFunc, middleware ...echo.MiddlewareFunc) *echo.Route {
// Combine into a new slice to avoid accidentally passing the same slice for
// multiple routes, which would lead to later add() calls overwriting the
// middleware from earlier calls.
return g.EchoGroup.Add(method, path, func(c echo.Context) error {
ctx := NewContext(c)
return handler(ctx)
})
}