Refactor bootstrap so it's decoupled from main function

This commit is contained in:
Marcos Lilljedahl
2017-08-08 10:35:53 -03:00
parent 24a87d4416
commit cbe5ede847
2 changed files with 28 additions and 8 deletions

View File

@@ -25,15 +25,13 @@ var core pwd.PWDApi
var e event.EventApi
var ws *socketio.Server
func Bootstrap() {
s, err := storage.NewFileStorage(config.SessionsFile)
e = event.NewLocalBroker()
func Bootstrap(storageInit func() storage.StorageApi, eventInit func() event.EventApi, factoryInit func(storage.StorageApi) docker.FactoryApi) {
s := storageInit()
f := docker.NewLocalCachedFactory(s)
e = eventInit()
f := factoryInit(s)
if err != nil && !os.IsNotExist(err) {
log.Fatal("Error initializing StorageAPI: ", err)
}
core = pwd.NewPWD(f, e, s)
sch, err := scheduler.NewScheduler(s, e, core)