tsviewer/main.go

49 lines
992 B
Go

package main
import (
"log"
"net/http"
"time"
"git.cliffbreak.de/haveachin/go-tsviewer/config"
"git.cliffbreak.de/haveachin/go-tsviewer/features/channel"
"git.cliffbreak.de/haveachin/go-tsviewer/features/client"
"git.cliffbreak.de/haveachin/go-tsviewer/service"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func Routes(s service.Service) *chi.Mux {
router := chi.NewRouter()
router.Use(
middleware.Logger,
middleware.Timeout(5*time.Second),
middleware.DefaultCompress,
middleware.RedirectSlashes,
middleware.Recoverer,
)
router.Route("/v1", func(r chi.Router) {
r.Mount("/channels", channel.Routes(s))
r.Mount("/clients", client.Routes(s))
})
return router
}
func main() {
config, err := config.New()
if err != nil {
log.Fatal(err)
}
service, err := service.New(*config)
if err != nil {
log.Fatal(err)
}
defer service.TSClient.Close()
router := Routes(*service)
log.Fatal("Handler: ", http.ListenAndServe(":8080", router))
}