-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
group.go
114 lines (103 loc) · 2.63 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package minima
/**
* @info The minima group structure
* @property {[]cacheroute} [route] The array of cached routes
* @property {[string} [prefix] The group prefix
*/
type Group struct {
route []*cacheRoute
prefix string
}
/**
* @info Creates a new minima group
* @return {Group}
*/
func NewGroup(prefix string) *Group {
return &Group{
route: make([]*cacheRoute, 0),
prefix: prefix,
}
}
func (g *Group) register(method string, path string, handler Handler) {
g.route = append(g.route, &cacheRoute{
method: method,
path: g.prefix + path,
handler: handler,
})
}
/**
* @info Adds route with Get method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Router}
*/
func (g *Group) Get(path string, handler Handler) *Group {
g.register("GET", path, handler)
return g
}
/**
* @info Adds route with Post method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Group}
*/
func (g *Group) Post(path string, handler Handler) *Group {
g.register("POST", path, handler)
return g
}
/**
* @info Adds route with Put method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Group}
*/
func (g *Group) Put(path string, handler Handler) *Group {
g.register("PUT", path, handler)
return g
}
/**
* @info Adds route with Patch method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Group}
*/
func (g *Group) Patch(path string, handler Handler) {
g.register("PATCH", path, handler)
}
/**
* @info Adds route with Options method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Group}
*/
func (g *Group) Options(path string, handler Handler) *Group {
g.register("OPTIONS", path, handler)
return g
}
/**
* @info Adds route with Head method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Group}
*/
func (g *Group) Head(path string, handler Handler) *Group {
g.register("HEAD", path, handler)
return g
}
/**
* @info Adds route with Delete method
* @param {string} [path] The route path
* @param {...Handler} [handler] The handler for the given route
* @returns {*Group}
*/
func (g *Group) Delete(path string, handler Handler) *Group {
g.register("DELETE", path, handler)
return g
}
/**
* @info Returns all routes for the group
* @return {[]cachRoute}
*/
func (g *Group) GetGroupRoutes() []*cacheRoute {
return g.route
}