package main import ( lucifer3 "git.aiterp.net/lucifer3/server" "git.aiterp.net/lucifer3/server/events" "git.aiterp.net/lucifer3/server/services" "git.aiterp.net/lucifer3/server/services/httpapiv1" "git.aiterp.net/lucifer3/server/services/hue" "git.aiterp.net/lucifer3/server/services/mysqldb" "git.aiterp.net/lucifer3/server/services/nanoleaf" "git.aiterp.net/lucifer3/server/services/uistate" "log" "os" "os/signal" "strconv" "syscall" ) func main() { bus := lucifer3.EventBus{} resolver := services.NewResolver() sceneMap := services.NewSceneMap(resolver) database, err := mysqldb.Connect( env("LUCIFER4_DB_HOST"), envInt("LUCIFER4_DB_PORT"), env("LUCIFER4_DB_USER"), env("LUCIFER4_DB_PASSWORD"), env("LUCIFER4_DB_SCHEMA"), ) if err != nil { log.Fatalln("Database failed", err) } httpAPI, err := httpapiv1.New(env("LUCIFER4_HTTP_LISTEN")) if err != nil { log.Fatalln("HTTP Listen failed", err) } bus.JoinPrivileged(resolver) bus.JoinPrivileged(sceneMap) bus.Join(services.NewEffectEnforcer(resolver, sceneMap)) bus.Join(nanoleaf.NewService()) bus.Join(hue.NewService()) bus.Join(uistate.NewService()) bus.Join(database) bus.Join(httpAPI) bus.RunEvent(events.Started{}) exitSignal := make(chan os.Signal) signal.Notify(exitSignal, os.Interrupt, os.Kill, syscall.SIGTERM) sig := <-exitSignal log.Println("Received signal", sig) } func env(key string) string { value := os.Getenv(key) if value == "" { log.Fatalln("Expected env:", key) } return value } func envInt(key string) int { value, err := strconv.Atoi(os.Getenv(key)) if err != nil { log.Fatalln("Expected numeric env:", key) } return value }