-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutergroup.go
48 lines (37 loc) · 1.47 KB
/
routergroup.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
37
38
39
40
41
42
43
44
45
46
47
48
// ==================================================
// Copyright (c) 2016 tacigar. All rights reserved.
// ==================================================
package mixo
type RouterGroup struct {
engine *Engine
Handlers []Handler
}
// --------------------------------------------------
func (routerGroup *RouterGroup) registerHandler(
methodName, relativePath string, handlers []Handler) {
// append router group's handlers and parameter handlers
newHandlers := append(routerGroup.Handlers, handlers...)
routerGroup.engine.addRoute(methodName, relativePath, newHandlers)
}
func (routerGroup *RouterGroup) GET(relativePath string, handlers ...Handler) {
routerGroup.registerHandler("GET", relativePath, handlers)
}
func (routerGroup *RouterGroup) POST(relativePath string, handlers ...Handler) {
routerGroup.registerHandler("POST", relativePath, handlers)
}
func (routerGroup *RouterGroup) PUT(relativePath string, handlers ...Handler) {
routerGroup.registerHandler("PUT", relativePath, handlers)
}
func (routerGroup *RouterGroup) DELETE(relativePath string, handlers ...Handler) {
routerGroup.registerHandler("DELETE", relativePath, handlers)
}
func (routerGroup *RouterGroup) Use(handlers ...Handler) {
routerGroup.Handlers = append(routerGroup.Handlers, handlers...)
}
// --------------------------------------------------
func (routerGroup *RouterGroup) Branch() *RouterGroup {
return &RouterGroup{
engine: routerGroup.engine,
Handlers: routerGroup.Handlers,
}
}