-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
49 lines (40 loc) · 1.21 KB
/
controller.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
package stgin
import (
"fmt"
"strings"
)
type Controller struct {
Name string
routes []Route
prefix string
requestListeners []RequestListener
responseListeners []ResponseListener
apiListeners []APIListener
}
func NewController(name string) *Controller {
return &Controller{
Name: name,
}
}
func (controller *Controller) SetRoutePrefix(prefix string) {
if strings.HasPrefix(prefix, "/") {
controller.prefix = prefix
} else {
controller.prefix = fmt.Sprintf("%v%v", "/", prefix)
}
}
func (controller *Controller) AddRoutes(routes ...Route) {
controller.routes = append(controller.routes, routes...)
}
func (controller *Controller) AddRequestListeners(listeners ...RequestListener) {
controller.requestListeners = append(controller.requestListeners, listeners...)
}
func (controller *Controller) AddResponseListener(listeners ...ResponseListener) {
controller.responseListeners = append(controller.responseListeners, listeners...)
}
func (controller *Controller) AddAPIListeners(listeners ...APIListener) {
controller.apiListeners = append(controller.apiListeners, listeners...)
}
func (controller *Controller) hasPrefix() bool {
return controller.prefix != ""
}