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.

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