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.

45 lines
1.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package app
  2. import (
  3. "context"
  4. "fmt"
  5. "git.aiterp.net/lucifer/new-server/app/api"
  6. "git.aiterp.net/lucifer/new-server/app/config"
  7. "git.aiterp.net/lucifer/new-server/app/services"
  8. "git.aiterp.net/lucifer/new-server/app/services/publisher"
  9. "git.aiterp.net/lucifer/new-server/models"
  10. "github.com/gin-gonic/gin"
  11. "log"
  12. "time"
  13. )
  14. func StartServer() {
  15. setupCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
  16. defer cancel()
  17. err := publisher.Initialize(setupCtx)
  18. if err != nil {
  19. log.Fatalln("Publish init failed:", err)
  20. return
  21. }
  22. services.StartEventHandler()
  23. services.ConnectToBridges()
  24. services.CheckNewDevices()
  25. gin.SetMode(gin.ReleaseMode)
  26. ginny := gin.New()
  27. apiGin := ginny.Group("/api")
  28. api.Bridges(apiGin.Group("/bridges"))
  29. api.Devices(apiGin.Group("/devices"))
  30. api.ColorPresets(apiGin.Group("/color-presets"))
  31. api.DriverKinds(apiGin.Group("/driver-kinds"))
  32. api.Events(apiGin.Group("/events"))
  33. api.EventHandlers(apiGin.Group("/event-handlers"))
  34. api.Scenes(apiGin.Group("/scenes"))
  35. models.TimeOfDayTimeZone = config.Location()
  36. log.Fatal(ginny.Run(fmt.Sprintf("0.0.0.0:%d", config.ServerPort())))
  37. }