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.

42 lines
1.0 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. "github.com/gin-gonic/gin"
  10. "log"
  11. "time"
  12. )
  13. func StartServer() {
  14. setupCtx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
  15. defer cancel()
  16. err := publisher.Initialize(setupCtx)
  17. if err != nil {
  18. log.Fatalln("Publish init failed:", err)
  19. return
  20. }
  21. services.StartEventHandler()
  22. services.ConnectToBridges()
  23. services.CheckNewDevices()
  24. gin.SetMode(gin.ReleaseMode)
  25. ginny := gin.New()
  26. apiGin := ginny.Group("/api")
  27. api.Bridges(apiGin.Group("/bridges"))
  28. api.Devices(apiGin.Group("/devices"))
  29. api.ColorPresets(apiGin.Group("/color-presets"))
  30. api.DriverKinds(apiGin.Group("/driver-kinds"))
  31. api.Events(apiGin.Group("/events"))
  32. api.EventHandlers(apiGin.Group("/event-handlers"))
  33. api.Scenes(apiGin.Group("/scenes"))
  34. log.Fatal(ginny.Run(fmt.Sprintf("0.0.0.0:%d", config.ServerPort())))
  35. }