-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
31 lines (25 loc) · 817 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
31
package chomolungma
import "strings"
type RouterGroup struct {
prefix string
middlewares []HandlerFunc
parent *RouterGroup
engine *Engine
}
// add middleware to group
func (g *RouterGroup) Use(middlewares ...HandlerFunc) {
g.middlewares = append(g.middlewares, middlewares...)
}
// add route to group
func (g *RouterGroup) addRoute(method string, pattern string, handler HandlerFunc) {
comb := strings.Replace(g.prefix+pattern, "//", "/", 1)
g.engine.r.addRoute(method, comb, handler)
}
// GET defines the method to add GET request
func (g *RouterGroup) GET(pattern string, handler HandlerFunc) {
g.addRoute("GET", pattern, handler)
}
// POST defines the method to add POST request
func (g *RouterGroup) POST(pattern string, handler HandlerFunc) {
g.addRoute("POST", pattern, handler)
}