2018-10-04 17:53:30 +02:00
|
|
|
package panelui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/GeertJohan/go.rice"
|
|
|
|
)
|
|
|
|
|
|
|
|
var templates, static *rice.Box
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
templates = rice.MustFindBox("res/templates")
|
|
|
|
static = rice.MustFindBox("res/static")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMux returns a ready-to-use mux
|
|
|
|
func GetMux() *http.ServeMux {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
user := r.Context().Value(keyUser)
|
|
|
|
if user == nil {
|
|
|
|
panic("Authentication middleware failed!")
|
|
|
|
}
|
|
|
|
templateExecute(w, r, "home.html", templates,
|
|
|
|
map[string]interface{}{"User": user})
|
|
|
|
})
|
2018-11-13 15:09:33 +01:00
|
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(static.HTTPBox())))
|
2018-10-04 17:53:30 +02:00
|
|
|
return mux
|
|
|
|
}
|