2019-05-26 19:32:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/config"
|
|
|
|
"git.cliffbreak.de/Cliffbreak/tsviewer/service"
|
|
|
|
"github.com/go-chi/chi"
|
|
|
|
"github.com/go-chi/chi/middleware"
|
|
|
|
"github.com/go-chi/cors"
|
|
|
|
)
|
|
|
|
|
2019-05-26 19:45:33 +00:00
|
|
|
func Routes(s *service.Service) *chi.Mux {
|
2019-05-26 19:32:16 +00:00
|
|
|
router := chi.NewRouter()
|
2019-05-26 19:45:33 +00:00
|
|
|
|
2019-05-26 19:32:16 +00:00
|
|
|
cors := cors.New(cors.Options{
|
|
|
|
AllowedOrigins: []string{"*"},
|
|
|
|
AllowedMethods: []string{"Get"},
|
|
|
|
})
|
2019-05-26 19:45:33 +00:00
|
|
|
|
2019-05-26 19:32:16 +00:00
|
|
|
router.Use(
|
|
|
|
middleware.Logger,
|
|
|
|
middleware.Timeout(5*time.Second),
|
|
|
|
middleware.DefaultCompress,
|
|
|
|
middleware.RedirectSlashes,
|
|
|
|
middleware.Recoverer,
|
|
|
|
|
|
|
|
cors.Handler,
|
|
|
|
)
|
|
|
|
|
|
|
|
router.Route("/", func(r chi.Router) {
|
2019-05-26 19:45:33 +00:00
|
|
|
//r.Mount("/channels", channel.APIRoutes(s))
|
2019-05-26 19:32:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return router
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.Println("Loading configurations...")
|
|
|
|
config, err := config.New()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2019-05-26 19:45:33 +00:00
|
|
|
return
|
2019-05-26 19:32:16 +00:00
|
|
|
}
|
|
|
|
log.Println("Configurations loaded!")
|
|
|
|
|
|
|
|
log.Println("Starting query service...")
|
|
|
|
service, err := service.New(*config)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2019-05-26 19:45:33 +00:00
|
|
|
return
|
2019-05-26 19:32:16 +00:00
|
|
|
}
|
|
|
|
defer service.TSClient.Close()
|
|
|
|
log.Println("Query service connected to", fmt.Sprintf("%s:%d!", config.ServerTS.IP, config.ServerTS.PortQuery))
|
|
|
|
|
2019-05-26 19:45:33 +00:00
|
|
|
router := Routes(service)
|
2019-05-26 19:32:16 +00:00
|
|
|
|
|
|
|
log.Println("Starting the web server locally on port", config.ServerWeb.Port)
|
|
|
|
log.Fatal("Handler: ", http.ListenAndServe(fmt.Sprintf(":%d", config.ServerWeb.Port), router))
|
|
|
|
}
|