2018-02-10 22:36:21 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-02-12 00:24:43 +00:00
|
|
|
"github.com/kirsle/blog/internal/middleware/auth"
|
|
|
|
"github.com/kirsle/blog/internal/render"
|
2018-02-10 22:36:21 +00:00
|
|
|
"github.com/urfave/negroni"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Register the initial setup routes.
|
|
|
|
func Register(r *mux.Router, authErrorFunc http.HandlerFunc) {
|
|
|
|
adminRouter := mux.NewRouter().PathPrefix("/admin").Subrouter().StrictSlash(true)
|
|
|
|
adminRouter.HandleFunc("/", indexHandler)
|
|
|
|
adminRouter.HandleFunc("/settings", settingsHandler)
|
|
|
|
adminRouter.HandleFunc("/editor", editorHandler)
|
|
|
|
|
|
|
|
r.PathPrefix("/admin").Handler(negroni.New(
|
|
|
|
negroni.HandlerFunc(auth.LoginRequired(authErrorFunc)),
|
|
|
|
negroni.Wrap(adminRouter),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
render.Template(w, r, "admin/index", nil)
|
|
|
|
}
|