-
Notifications
You must be signed in to change notification settings - Fork 11
/
group.go
108 lines (86 loc) · 2.66 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
package echo
type (
Group struct {
prefix string
middleware []interface{}
echo *Echo
}
)
func (g *Group) URL(h interface{}, params ...interface{}) string {
return g.echo.URL(h, params...)
}
func (g *Group) SetRenderer(r Renderer) {
g.echo.renderer = r
}
func (g *Group) Any(path string, h interface{}, middleware ...interface{}) {
for _, m := range methods {
g.add(m, path, h, middleware...)
}
}
func (g *Group) Route(methods string, path string, h interface{}, middleware ...interface{}) {
g.Match(httpMethodRegexp.Split(methods, -1), path, h, middleware...)
}
func (g *Group) Match(methods []string, path string, h interface{}, middleware ...interface{}) {
for _, m := range methods {
g.add(m, path, h, middleware...)
}
}
func (g *Group) Use(middleware ...interface{}) {
for _, m := range middleware {
g.echo.ValidMiddleware(m)
g.middleware = append(g.middleware, m)
}
}
func (g *Group) Pre(middleware ...interface{}) {
g.PreUse(middleware...)
}
func (g *Group) PreUse(middleware ...interface{}) {
var middlewares []interface{}
for _, m := range middleware {
g.echo.ValidMiddleware(m)
middlewares = append(middlewares, m)
}
g.middleware = append(middlewares, g.middleware...)
}
func (g *Group) Connect(path string, h interface{}, m ...interface{}) {
g.add(CONNECT, path, h, m...)
}
func (g *Group) Delete(path string, h interface{}, m ...interface{}) {
g.add(DELETE, path, h, m...)
}
func (g *Group) Get(path string, h interface{}, m ...interface{}) {
g.add(GET, path, h, m...)
}
func (g *Group) Head(path string, h interface{}, m ...interface{}) {
g.add(HEAD, path, h, m...)
}
func (g *Group) Options(path string, h interface{}, m ...interface{}) {
g.add(OPTIONS, path, h, m...)
}
func (g *Group) Patch(path string, h interface{}, m ...interface{}) {
g.add(PATCH, path, h, m...)
}
func (g *Group) Post(path string, h interface{}, m ...interface{}) {
g.add(POST, path, h, m...)
}
func (g *Group) Put(path string, h interface{}, m ...interface{}) {
g.add(PUT, path, h, m...)
}
func (g *Group) Trace(path string, h interface{}, m ...interface{}) {
g.add(TRACE, path, h, m...)
}
func (g *Group) Group(prefix string, m ...interface{}) *Group {
return g.echo.Group(g.prefix+prefix, m...)
}
func (g *Group) Prefix() string {
return g.prefix
}
func (g *Group) add(method, path string, h interface{}, middleware ...interface{}) {
// Combine into a new slice to avoid accidentally passing the same slice for
// multiple routes, which would lead to later add() calls overwriting the
// middleware from earlier calls.
m := []interface{}{}
m = append(m, g.middleware...)
m = append(m, middleware...)
g.echo.add(method, g.prefix+path, h, m...)
}