This repository has been archived on 2019-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
scoreboard/main.go

63 lines
1.3 KiB
Go

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"
)
func Routes(s *service.Service) *chi.Mux {
router := chi.NewRouter()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"Get"},
})
router.Use(
middleware.Logger,
middleware.Timeout(5*time.Second),
middleware.DefaultCompress,
middleware.RedirectSlashes,
middleware.Recoverer,
cors.Handler,
)
router.Route("/", func(r chi.Router) {
//r.Mount("/channels", channel.APIRoutes(s))
})
return router
}
func main() {
log.Println("Loading configurations...")
config, err := config.New()
if err != nil {
log.Fatal(err)
return
}
log.Println("Configurations loaded!")
log.Println("Starting query service...")
service, err := service.New(*config)
if err != nil {
log.Fatal(err)
return
}
defer service.TSClient.Close()
log.Println("Query service connected to", fmt.Sprintf("%s:%d!", config.ServerTS.IP, config.ServerTS.PortQuery))
router := Routes(service)
log.Println("Starting the web server locally on port", config.ServerWeb.Port)
log.Fatal("Handler: ", http.ListenAndServe(fmt.Sprintf(":%d", config.ServerWeb.Port), router))
}