This commit is contained in:
Henrique Dias 2015-09-12 18:58:10 +01:00
parent 924a5fd900
commit 8f97788f89
1 changed files with 16 additions and 12 deletions

28
hugo.go
View File

@ -2,6 +2,7 @@ package hugo
import ( import (
"net/http" "net/http"
"strings"
"github.com/spf13/hugo/commands" "github.com/spf13/hugo/commands"
@ -14,26 +15,29 @@ func Setup(c *setup.Controller) (middleware.Middleware, error) {
commands.Execute() commands.Execute()
return func(next middleware.Handler) middleware.Handler { return func(next middleware.Handler) middleware.Handler {
return &handler{ return &handler{Next: next}
Next: next,
}
}, nil }, nil
} }
type handler struct{ Next middleware.Handler } type handler struct{ Next middleware.Handler }
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") { if middleware.Path(r.URL.Path).Matches("/admin") {
a := new(adminHandler)
return a.ServeHTTP(w, r) if middleware.Path(r.URL.Path).Matches("/admin/new") {
w.Write([]byte("New"))
} else if middleware.Path(r.URL.Path).Matches("/admin/edit") {
var fileName string
fileName = strings.Replace(r.URL.Path, "/admin/edit", "", 1)
w.Write([]byte("Edit " + fileName))
} else {
w.Write([]byte("Admin"))
}
return 200, nil
} }
return h.Next.ServeHTTP(w, r) return h.Next.ServeHTTP(w, r)
} }
func (a adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
w.Write([]byte("Admin area"))
return 200, nil
}