-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
47 lines (39 loc) · 1.22 KB
/
options.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
package routegroup
import "net/http"
type Option func(*group)
// WithMux sets the mux for the group. (default: http.NewServeMux()
func WithMux(mux *http.ServeMux) Option {
return func(g *group) {
g.ServeMux = mux
}
}
// WithMiddlewares adds the middlewares for the group.
func WithMiddlewares(middlewares ...func(http.Handler) http.Handler) Option {
return func(g *group) {
g.Middlewares = append(g.Middlewares, middlewares...)
}
}
// WithPrefix sets the prefix for the group from root level.
func WithPrefix(prefix string) Option {
return func(g *group) {
g.Prefix = prefix
}
}
// WithSubPrefix sets the sub prefix for the group from parent level.
func WithSubPrefix(prefix string) Option {
return func(g *group) {
g.Prefix = g.Prefix + prefix
}
}
// WithRegisterCallback sets the callback that is called when a route is registered.
func WithRegisterCallback(callback func(pattern string)) Option {
return func(g *group) {
g.RegisterCallback = callback
}
}
// WithRegisterPanicCallback sets the callback that is called when a panic occurs while registering a route.
func WithRegisterPanicCallback(callback func(pattern string, err interface{})) Option {
return func(g *group) {
g.RegisterPanicCallback = callback
}
}