-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
40 lines (34 loc) · 1.14 KB
/
router.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
package cin
import (
consoleController "github.com/cinling/cin/console/controllers"
"github.com/cinling/cin/core/base"
"github.com/cinling/cin/core/models"
)
// 路由器
type router struct {
controllerList []base.ControllerInterface
consoleControllerList []base.ControllerInterface
onWebsocketMessageHandler func(conn *models.Context, recvMessage []byte)
}
// 新建路由器
func newRouter() *router {
r := new(router)
r.controllerList = []base.ControllerInterface{}
r.onWebsocketMessageHandler = nil
r.consoleControllerList = []base.ControllerInterface{}
r.registerDefaultConsoleController()
return r
}
// 写入默认的命令行控制器
func (r *router) registerDefaultConsoleController() {
r.RegisterConsole(new(consoleController.MigrateController))
r.RegisterConsole(new(consoleController.XormController))
}
// 注册控制器
func (r *router) Register(controller base.ControllerInterface) {
r.controllerList = append(r.controllerList, controller)
}
// 注册命令行控制器
func (r *router) RegisterConsole(controller base.ControllerInterface) {
r.consoleControllerList = append(r.consoleControllerList, controller)
}