1
0
Fork 0
allowances/routes.go

58 Zeilen
1.1 KiB
Go

package allowances
import (
"net/http"
"github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/context"
"github.com/prometheus/client_golang/prometheus"
)
var prefix map[string]string
func addRoutes(sm *http.ServeMux, a *Allowances, staticFiles string) {
prefix = map[string]string{
"static": "/s/",
"auth": "/api/v0/auth/",
"reset": "/api/v0/auth/reset/",
"add": "/add/",
"login": "/login/",
"logout": "/logout/",
}
sm.HandleFunc("/", a.protected(a.home))
sm.HandleFunc(prefix["login"], a.login)
sm.HandleFunc(prefix["logout"], a.protected(a.logout))
sm.HandleFunc(prefix["add"], a.protected(a.add))
if staticFiles == "" {
sm.Handle(
prefix["static"],
http.StripPrefix(
prefix["static"],
http.FileServer(
&assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
Prefix: "static",
},
),
),
)
} else {
sm.Handle(
prefix["static"],
http.StripPrefix(
prefix["static"],
http.FileServer(http.Dir(staticFiles)),
),
)
}
sm.Handle("/metrics", prometheus.Handler())
context.ClearHandler(sm)
}