-
Notifications
You must be signed in to change notification settings - Fork 1
/
group.go
44 lines (33 loc) · 939 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
32
33
34
35
36
37
38
39
40
41
42
43
44
package router
import (
"net/http"
"path"
"strings"
)
type group struct {
routerEngine *router
basePath string
}
func (g *group) register(m method, uri string, handler http.HandlerFunc) {
uri = strings.Trim(path.Join(g.basePath, uri), pathSeparator)
g.routerEngine.register(m, uri, handler)
}
func (g *group) GET(uri string, handler http.HandlerFunc) {
g.register(GET, uri, handler)
}
func (g *group) POST(uri string, handler http.HandlerFunc) {
g.register(POST, uri, handler)
}
func (g *group) PUT(uri string, handler http.HandlerFunc) {
g.register(PUT, uri, handler)
}
func (g *group) PATCH(uri string, handler http.HandlerFunc) {
g.register(PATCH, uri, handler)
}
func (g *group) DELETE(uri string, handler http.HandlerFunc) {
g.register(DELETE, uri, handler)
}
func (g *group) Group(uri string) RouteRegistrar {
uri = path.Join(g.basePath, uri)
return &group{basePath: uri, routerEngine: g.routerEngine}
}