forked from boyska/feedpanel
30 lines
634 B
Go
30 lines
634 B
Go
|
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})
|
||
|
})
|
||
|
mux.HandleFunc("/static", static.HTTPBox())
|
||
|
return mux
|
||
|
}
|