blog/core/internal/controllers/admin/admin.go
Noah Petherbridge eb1880d348 Break out some controllers and move mail to subpackage
Controllers moved into sub-packages:
* Initial setup
* Admin routes
* Auth login/out routes
* Contact
2018-02-10 14:36:21 -08:00

28 lines
774 B
Go

package admin
import (
"net/http"
"github.com/gorilla/mux"
"github.com/kirsle/blog/core/internal/middleware/auth"
"github.com/kirsle/blog/core/internal/render"
"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)
}