From b4cdd27fa3da785523d041d20dfdec86d03e26ee Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 12 Sep 2015 13:05:31 +0100 Subject: [PATCH] admin handler --- hugo.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/hugo.go b/hugo.go index 8439950f..420434b7 100644 --- a/hugo.go +++ b/hugo.go @@ -9,10 +9,9 @@ import ( "github.com/mholt/caddy/middleware" ) +// Setup function func Setup(c *setup.Controller) (middleware.Middleware, error) { - for c.Next() { - commands.Execute() - } + commands.Execute() return func(next middleware.Handler) middleware.Handler { return &handler{} @@ -20,8 +19,21 @@ func Setup(c *setup.Controller) (middleware.Middleware, error) { } type handler struct{} +type adminHandler struct{} 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) + + return 200, nil +} + +func (a adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { + w.Write([]byte("Admin area")) return 200, nil }