-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_group.go
36 lines (33 loc) · 1.64 KB
/
router_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
31
32
33
34
35
36
package chain
type Group interface {
GET(route string, handle any) error
HEAD(route string, handle any) error
OPTIONS(route string, handle any) error
POST(route string, handle any) error
PUT(route string, handle any) error
PATCH(route string, handle any) error
DELETE(route string, handle any) error
Use(args ...any) Group
Group(route string) Group
Handle(method string, route string, handle any) error
Configure(route string, configurator RouteConfigurator)
}
type RouterGroup struct {
p string
r *Router
}
func (r *RouterGroup) GET(route string, handle any) error { return r.r.GET(r.p+route, handle) }
func (r *RouterGroup) HEAD(route string, handle any) error { return r.r.HEAD(r.p+route, handle) }
func (r *RouterGroup) OPTIONS(route string, handle any) error { return r.r.OPTIONS(r.p+route, handle) }
func (r *RouterGroup) POST(route string, handle any) error { return r.r.POST(r.p+route, handle) }
func (r *RouterGroup) PUT(route string, handle any) error { return r.r.PUT(r.p+route, handle) }
func (r *RouterGroup) PATCH(route string, handle any) error { return r.r.PATCH(r.p+route, handle) }
func (r *RouterGroup) DELETE(route string, handle any) error { return r.r.DELETE(r.p+route, handle) }
func (r *RouterGroup) Use(args ...any) Group { return r.r.Use(args...) }
func (r *RouterGroup) Group(route string) Group { return &RouterGroup{r.p + route, r.r} }
func (r *RouterGroup) Handle(method string, route string, handle any) error {
return r.r.Handle(method, r.p+route, handle)
}
func (r *RouterGroup) Configure(route string, configurator RouteConfigurator) {
r.r.Configure(r.p+route, configurator)
}