-
Notifications
You must be signed in to change notification settings - Fork 2
/
group.go
86 lines (70 loc) · 2.69 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package fresh
import (
"path/filepath"
)
type (
Group interface {
Rest
Group(string) Group
After(...HandlerFunc) Group
Before(...HandlerFunc) Group
}
group struct {
parent *fresh
route *route
}
)
// Group registration
func (g *group) Group(path string) Group {
return g.parent.Group(filepath.Join(g.route.path, path)).After(g.route.after...).Before(g.route.before...)
}
// WS api registration
func (g *group) WS(path string, handler HandlerFunc) Handler {
return g.parent.WS(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// Register a resource (get, post, put, delete)
func (g *group) CRUD(path string, h ...HandlerFunc) Resource {
return g.parent.CRUD(filepath.Join(g.route.path, path), h...).After(g.route.after...).Before(g.route.before...)
}
// GET api registration
func (g *group) GET(path string, handler HandlerFunc) Handler {
return g.parent.GET(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// PUT api registration
func (g *group) PUT(path string, handler HandlerFunc) Handler {
return g.parent.PUT(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// POST api registration
func (g *group) POST(path string, handler HandlerFunc) Handler {
return g.parent.POST(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// TRACE api registration
func (g *group) TRACE(path string, handler HandlerFunc) Handler {
return g.parent.TRACE(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// PATCH api registration
func (g *group) PATCH(path string, handler HandlerFunc) Handler {
return g.parent.PATCH(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// DELETE api registration
func (g *group) DELETE(path string, handler HandlerFunc) Handler {
return g.parent.DELETE(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// OPTIONS api registration
func (g *group) OPTIONS(path string, handler HandlerFunc) Handler {
return g.parent.OPTIONS(filepath.Join(g.route.path, path), handler).After(g.route.after...).Before(g.route.before...)
}
// ASSETS serve a list of static files. Array of files or directories TODO write logic
func (g *group) STATIC(static map[string]string) {
g.parent.STATIC(static)
}
// After middleware
func (g *group) After(middleware ...HandlerFunc) Group {
g.route.after = append(g.route.after, middleware...)
return g
}
// Before middleware
func (g *group) Before(middleware ...HandlerFunc) Group {
g.route.before = append(g.route.before, middleware...)
return g
}