Refactor bootstrap so it's decoupled from main function
This commit is contained in:
24
api.go
24
api.go
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user