-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 1.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"log"
"net/http"
"github.com/booua/dashboard-hub/backend/services/cron"
firebasemodule "github.com/booua/dashboard-hub/backend/services/firebase"
"github.com/booua/dashboard-hub/backend/services/rest"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/render"
)
func Routes() *chi.Mux {
router := chi.NewRouter()
router.Use(
render.SetContentType(render.ContentTypeJSON),
middleware.Logger,
middleware.DefaultCompress,
middleware.RedirectSlashes,
middleware.Recoverer,
)
router.Route("/v1", func(r chi.Router) {
r.Mount("/dashboard-hub/blinds/", rest.BlindsActionsRoutes())
r.Mount("/dashboard-hub/status/", rest.StatusRoutes())
r.Mount("/dashboard-hub/time/", rest.SetupTimeRoutes())
})
return router
}
func main() {
router := Routes()
walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Printf("%s %s\n", method, route)
return nil
}
if err := chi.Walk(router, walkFunc); err != nil {
log.Panicf("Logging error: %s\n", err.Error())
}
cron.SetupCronJobForClosing(firebasemodule.GetClosingTime())
cron.SetupCronJobForOpening(firebasemodule.GetOpeningTime())
log.Fatal(http.ListenAndServe(":8080", router))
}