54 lines
1009 B
Go
54 lines
1009 B
Go
|
package allowances
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/elazarl/go-bindata-assetfs"
|
||
|
"github.com/gorilla/context"
|
||
|
)
|
||
|
|
||
|
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,
|
||
|
Prefix: "static",
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
)
|
||
|
|
||
|
} else {
|
||
|
sm.Handle(
|
||
|
prefix["static"],
|
||
|
http.StripPrefix(
|
||
|
prefix["static"],
|
||
|
http.FileServer(http.Dir(staticFiles)),
|
||
|
),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
context.ClearHandler(sm)
|
||
|
}
|