Skip to content
Snippets Groups Projects
Select Git revision
  • 1808aad2c37283d22846fb21cb56cb21afd4dbd7
  • master default protected
  • entra protected
  • kasszasch protected
  • radlaci97-modern-web
  • revert-8b053a7c
  • manifest-background-color
  • 18-ui-pimping protected
  • payout protected
  • v1.8.5 protected
  • v1.8.4 protected
  • v1.8.3 protected
  • v1.8.2 protected
  • v1.8.1 protected
  • v1.8.0 protected
  • v1.7.1 protected
  • v1.7.0 protected
  • v1.6.21 protected
  • v1.6.20 protected
  • v1.6.19 protected
  • v1.6.18 protected
  • v1.6.17 protected
  • v1.6.16 protected
  • v1.6.15 protected
  • v1.16.15 protected
  • v1.6.14 protected
  • v1.6.13 protected
  • v1.6.12 protected
  • v1.6.11 protected
29 results

main.go

Blame
  • 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()
    }