Major refactor
- use embedded static assets - added pw management subcommands
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user