keeping track of my children's money since 2013
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1KB

  1. package allowances
  2. import (
  3. "net/http"
  4. "github.com/elazarl/go-bindata-assetfs"
  5. "github.com/gorilla/context"
  6. "github.com/prometheus/client_golang/prometheus"
  7. )
  8. var prefix map[string]string
  9. func addRoutes(sm *http.ServeMux, a *Allowances, staticFiles string) {
  10. prefix = map[string]string{
  11. "static": "/s/",
  12. "auth": "/api/v0/auth/",
  13. "reset": "/api/v0/auth/reset/",
  14. "add": "/add/",
  15. "login": "/login/",
  16. "logout": "/logout/",
  17. }
  18. sm.HandleFunc("/", a.protected(a.home))
  19. sm.HandleFunc(prefix["login"], a.login)
  20. sm.HandleFunc(prefix["logout"], a.protected(a.logout))
  21. sm.HandleFunc(prefix["add"], a.protected(a.add))
  22. if staticFiles == "" {
  23. sm.Handle(
  24. prefix["static"],
  25. http.StripPrefix(
  26. prefix["static"],
  27. http.FileServer(
  28. &assetfs.AssetFS{
  29. Asset: Asset,
  30. AssetDir: AssetDir,
  31. AssetInfo: AssetInfo,
  32. Prefix: "static",
  33. },
  34. ),
  35. ),
  36. )
  37. } else {
  38. sm.Handle(
  39. prefix["static"],
  40. http.StripPrefix(
  41. prefix["static"],
  42. http.FileServer(http.Dir(staticFiles)),
  43. ),
  44. )
  45. }
  46. sm.Handle("/metrics", prometheus.Handler())
  47. context.ClearHandler(sm)
  48. }