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

  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. "strconv"
  14. "time"
  15. )
  16. func main() {
  17. bus := lucifer3.EventBus{}
  18. resolver := services.NewResolver()
  19. sceneMap := services.NewSceneMap(resolver)
  20. database, err := mysqldb.Connect(
  21. env("LUCIFER4_DB_HOST"),
  22. envInt("LUCIFER4_DB_PORT"),
  23. env("LUCIFER4_DB_USER"),
  24. env("LUCIFER4_DB_PASSWORD"),
  25. env("LUCIFER4_DB_SCHEMA"),
  26. )
  27. if err != nil {
  28. log.Fatalln("Database failed", err)
  29. }
  30. httpAPI, err := httpapiv1.New(env("LUCIFER4_HTTP_LISTEN"))
  31. if err != nil {
  32. log.Fatalln("HTTP Listen failed", err)
  33. }
  34. bus.JoinPrivileged(resolver)
  35. bus.JoinPrivileged(sceneMap)
  36. bus.Join(services.NewEffectEnforcer(resolver, sceneMap))
  37. bus.Join(nanoleaf.NewService())
  38. bus.Join(hue.NewService())
  39. bus.Join(uistate.NewService())
  40. bus.Join(database)
  41. bus.Join(httpAPI)
  42. bus.RunEvent(events.Started{})
  43. time.Sleep(time.Hour * 16)
  44. }
  45. func env(key string) string {
  46. value := os.Getenv(key)
  47. if value == "" {
  48. log.Fatalln("Expected env:", key)
  49. }
  50. return value
  51. }
  52. func envInt(key string) int {
  53. value, err := strconv.Atoi(os.Getenv(key))
  54. if err != nil {
  55. log.Fatalln("Expected numeric env:", key)
  56. }
  57. return value
  58. }