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.

74 lines
1.6 KiB

  1. package main
  2. import (
  3. lucifer3 "git.aiterp.net/lucifer3/server"
  4. "git.aiterp.net/lucifer3/server/events"
  5. "git.aiterp.net/lucifer3/server/services"
  6. "git.aiterp.net/lucifer3/server/services/httpapiv1"
  7. "git.aiterp.net/lucifer3/server/services/hue"
  8. "git.aiterp.net/lucifer3/server/services/mysqldb"
  9. "git.aiterp.net/lucifer3/server/services/nanoleaf"
  10. "git.aiterp.net/lucifer3/server/services/uistate"
  11. "log"
  12. "os"
  13. "os/signal"
  14. "strconv"
  15. "syscall"
  16. )
  17. func main() {
  18. bus := lucifer3.EventBus{}
  19. resolver := services.NewResolver()
  20. sceneMap := services.NewSceneMap(resolver)
  21. database, err := mysqldb.Connect(
  22. env("LUCIFER4_DB_HOST"),
  23. envInt("LUCIFER4_DB_PORT"),
  24. env("LUCIFER4_DB_USER"),
  25. env("LUCIFER4_DB_PASSWORD"),
  26. env("LUCIFER4_DB_SCHEMA"),
  27. )
  28. if err != nil {
  29. log.Fatalln("Database failed", err)
  30. }
  31. httpAPI, err := httpapiv1.New(env("LUCIFER4_HTTP_LISTEN"))
  32. if err != nil {
  33. log.Fatalln("HTTP Listen failed", err)
  34. }
  35. bus.JoinPrivileged(resolver)
  36. bus.JoinPrivileged(sceneMap)
  37. bus.Join(services.NewEffectEnforcer(resolver, sceneMap))
  38. bus.Join(nanoleaf.NewService())
  39. bus.Join(hue.NewService())
  40. bus.Join(uistate.NewService())
  41. bus.Join(database)
  42. bus.Join(httpAPI)
  43. bus.RunEvent(events.Started{})
  44. exitSignal := make(chan os.Signal)
  45. signal.Notify(exitSignal, os.Interrupt, os.Kill, syscall.SIGTERM)
  46. sig := <-exitSignal
  47. log.Println("Received signal", sig)
  48. }
  49. func env(key string) string {
  50. value := os.Getenv(key)
  51. if value == "" {
  52. log.Fatalln("Expected env:", key)
  53. }
  54. return value
  55. }
  56. func envInt(key string) int {
  57. value, err := strconv.Atoi(os.Getenv(key))
  58. if err != nil {
  59. log.Fatalln("Expected numeric env:", key)
  60. }
  61. return value
  62. }