2019-01-14 20:07:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2019-01-17 00:35:51 +00:00
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/config"
|
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/features/channel"
|
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/features/client"
|
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/features/server"
|
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/service"
|
2019-01-14 20:07:11 +00:00
|
|
|
"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) {
|
2019-01-16 21:01:48 +00:00
|
|
|
r.Mount("/channels", channel.APIRoutes(s))
|
|
|
|
r.Mount("/clients", client.APIRoutes(s))
|
|
|
|
r.Mount("/server", server.APIRoutes(s))
|
2019-01-14 20:07:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2019-01-15 00:46:39 +00:00
|
|
|
defer service.TSClient.Close()
|
2019-01-14 20:07:11 +00:00
|
|
|
|
|
|
|
router := Routes(*service)
|
|
|
|
|
|
|
|
log.Fatal("Handler: ", http.ListenAndServe(":8080", router))
|
|
|
|
}
|