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

24
api.go
View File

@@ -1,12 +1,34 @@
package main
import (
"log"
"os"
"github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/handlers"
"github.com/play-with-docker/play-with-docker/storage"
)
func main() {
config.ParseFlags()
handlers.Bootstrap()
handlers.Bootstrap(initStorage, initEvent, initFactory)
handlers.Register()
}
func initStorage() storage.StorageApi {
s, err := storage.NewFileStorage(config.SessionsFile)
if err != nil && !os.IsNotExist(err) {
log.Fatal("Error initializing StorageAPI: ", err)
}
return s
}
func initEvent() event.EventApi {
return event.NewLocalBroker()
}
func initFactory(s storage.StorageApi) docker.FactoryApi {
return docker.NewLocalCachedFactory(s)
}