Select Git revision
main.go 1.65 KiB
package main
import (
"flag"
"git.sch.bme.hu/disappointment-industries/becskasszasch/admin"
"git.sch.bme.hu/disappointment-industries/becskasszasch/auth"
"git.sch.bme.hu/disappointment-industries/becskasszasch/helpers"
"git.sch.bme.hu/disappointment-industries/becskasszasch/history"
"git.sch.bme.hu/disappointment-industries/becskasszasch/homepage"
"git.sch.bme.hu/disappointment-industries/becskasszasch/topup"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gitlab.com/MikeTTh/env"
"gitlab.com/MikeTTh/graceful"
"net/http"
"os"
"syscall"
)
func init() {
graceful.AddHook(func(s os.Signal, done func()) {
helpers.Logger.Println("stopped server")
done()
})
}
func main() {
flag.Parse()
graceful.Listen(syscall.SIGINT, syscall.SIGTERM)
//TODO: mutexek
mux := http.NewServeMux()
mux.Handle("/static/", http.FileServer(http.Dir(".")))
mux.Handle("/login/", auth.LoginHandler)
mux.HandleFunc("/logout/", auth.LogoutHandler)
mux.Handle("/theme/", http.StripPrefix("/theme", http.HandlerFunc(homepage.ThemeHandler)))
mux.Handle("/new/", http.StripPrefix("/new", http.HandlerFunc(homepage.NewHandler)))
mux.Handle("/topup/", topup.Handler)
//mux.HandleFunc("/topup/api/", topup.PayPalHandler)
mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/metrics/", promhttp.Handler())
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler))
mux.HandleFunc("/history/", history.Handler)
mux.HandleFunc("/", homepage.Handler)
//mux.HandleFunc("/new/", homepage.NewHandler)
helpers.Logger.Println("started server")
e := http.ListenAndServe(env.String("LISTEN", ":8080"), mux)
if e != nil {
helpers.Logger.Println(e)
}
graceful.RunHooks()
}