admin handler

This commit is contained in:
Henrique Dias 2015-09-12 13:05:31 +01:00
parent 86f1554904
commit b4cdd27fa3
1 changed files with 15 additions and 3 deletions

18
hugo.go
View File

@ -9,10 +9,9 @@ import (
"github.com/mholt/caddy/middleware" "github.com/mholt/caddy/middleware"
) )
// Setup function
func Setup(c *setup.Controller) (middleware.Middleware, error) { func Setup(c *setup.Controller) (middleware.Middleware, error) {
for c.Next() { commands.Execute()
commands.Execute()
}
return func(next middleware.Handler) middleware.Handler { return func(next middleware.Handler) middleware.Handler {
return &handler{} return &handler{}
@ -20,8 +19,21 @@ func Setup(c *setup.Controller) (middleware.Middleware, error) {
} }
type handler struct{} type handler struct{}
type adminHandler struct{}
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
// do path matching
if middleware.Path(r.URL.Path).Matches("/admin") {
a := new(adminHandler)
return a.ServeHTTP(w, r)
}
http.ServeFile(w, r, "public"+r.URL.Path) http.ServeFile(w, r, "public"+r.URL.Path)
return 200, nil
}
func (a adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
w.Write([]byte("Admin area"))
return 200, nil return 200, nil
} }