You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 lines
1.5 KiB

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"
"strconv"
"time"
)
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{})
time.Sleep(time.Hour * 16)
}
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
}