main.go 678 B

1234567891011121314151617181920212223242526272829
  1. package panelui
  2. import (
  3. "net/http"
  4. "github.com/GeertJohan/go.rice"
  5. )
  6. var templates, static *rice.Box
  7. func init() {
  8. templates = rice.MustFindBox("res/templates")
  9. static = rice.MustFindBox("res/static")
  10. }
  11. // GetMux returns a ready-to-use mux
  12. func GetMux() *http.ServeMux {
  13. mux := http.NewServeMux()
  14. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  15. user := r.Context().Value(keyUser)
  16. if user == nil {
  17. panic("Authentication middleware failed!")
  18. }
  19. templateExecute(w, r, "home.html", templates,
  20. map[string]interface{}{"User": user})
  21. })
  22. mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(static.HTTPBox())))
  23. return mux
  24. }