-
Notifications
You must be signed in to change notification settings - Fork 4
/
fab.go
77 lines (62 loc) · 1.96 KB
/
fab.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
package fab
import (
"github.com/kooinam/fab.io/actors"
"github.com/kooinam/fab.io/controllers"
"github.com/kooinam/fab.io/models"
"github.com/kooinam/fab.io/views"
)
var engine *Engine
// Engine is the core engine for fab.io
type Engine struct {
modelManager *models.Manager
controllerManager *controllers.Manager
viewManager *views.Manager
actorManager *actors.Manager
configuration *Configuration
}
// Setup used to setup engine
func Setup() {
engine = &Engine{
modelManager: &models.Manager{},
controllerManager: &controllers.Manager{},
viewManager: &views.Manager{},
actorManager: &actors.Manager{},
}
engine.modelManager.Setup()
engine.viewManager.Setup()
engine.controllerManager.Setup(ViewManager())
engine.actorManager.Setup(ViewManager())
serveStats()
}
// ConfigureAndServe used to setup applications and start server
// register adapters, collections for modelmanager
// register controllers, routings for controllermanager
// register views for viewmanager
// configure configuration
func ConfigureAndServe(initializer Intializer) {
Setup()
engine.configuration = &Configuration{}
initializer.Configure(engine.configuration)
initializer.RegisterAdapters(ModelManager())
initializer.RegisterCollections(ModelManager())
initializer.RegisterControllers(ControllerManager())
initializer.RegisterViews(ViewManager())
initializer.BeforeServe()
ControllerManager().Serve(engine.configuration.port, engine.configuration.httpHandler)
}
// ControllerManager used to retrieve controller manager
func ControllerManager() *controllers.Manager {
return engine.controllerManager
}
// ActorManager used to retrieve actor manager
func ActorManager() *actors.Manager {
return engine.actorManager
}
// ModelManager used to retrieve model manager
func ModelManager() *models.Manager {
return engine.modelManager
}
// ViewManager used to retrieve view manager
func ViewManager() *views.Manager {
return engine.viewManager
}