Skip to content

Commit e09fc86

Browse files
committed
Implement routes group
1 parent 5c85885 commit e09fc86

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

group.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package pulse
2+
3+
import "fmt"
4+
5+
type Group struct {
6+
prefix string
7+
router *Router
8+
}
9+
10+
func (g *Group) Group(prefix string) *Group {
11+
return &Group{
12+
prefix: g.prefix + prefix,
13+
router: g.router,
14+
}
15+
}
16+
17+
func (g *Group) Use(middleware Middleware) {
18+
g.router.Use(g.prefix, middleware)
19+
}
20+
21+
func (g *Group) GET(path string, handlers ...Handler) {
22+
fmt.Println(g.prefix + path)
23+
g.router.Get(g.prefix+path, handlers...)
24+
}
25+
26+
func (g *Group) POST(path string, handlers ...Handler) {
27+
g.router.Post(g.prefix+path, handlers...)
28+
}
29+
30+
func (g *Group) PUT(path string, handlers ...Handler) {
31+
g.router.Put(g.prefix+path, handlers...)
32+
}
33+
34+
func (g *Group) DELETE(path string, handlers ...Handler) {
35+
g.router.Delete(g.prefix+path, handlers...)
36+
}
37+
38+
func (g *Group) PATCH(path string, handlers ...Handler) {
39+
g.router.Patch(g.prefix+path, handlers...)
40+
}
41+
42+
func (g *Group) OPTIONS(path string, handlers ...Handler) {
43+
g.router.Options(g.prefix+path, handlers...)
44+
}
45+
46+
func (g *Group) HEAD(path string, handlers ...Handler) {
47+
g.router.Head(g.prefix+path, handlers...)
48+
}
49+
50+
func (g *Group) Static(path, root string, config *Static) {
51+
g.router.Static(g.prefix+path, root, config)
52+
}

0 commit comments

Comments
 (0)