From fb0e4d79b296e4bba10454f5e84a5e3aee2266be Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 6 Mar 2016 13:14:05 +0000 Subject: [PATCH] progresses on #41 --- git/git.go | 18 ++++++++++++++++++ git/post.go | 15 +++++++++++++++ hugo.go | 6 ++++++ 3 files changed, 39 insertions(+) create mode 100644 git/git.go create mode 100644 git/post.go diff --git a/git/git.go b/git/git.go new file mode 100644 index 00000000..38d84adb --- /dev/null +++ b/git/git.go @@ -0,0 +1,18 @@ +package git + +import ( + "errors" + "net/http" + + "github.com/hacdias/caddy-hugo/config" +) + +// ServeHTTP is used to serve the content of GIT API. +func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) { + switch r.Method { + case "POST": + return POST(w, r, c) + default: + return 400, errors.New("Invalid method.") + } +} diff --git a/git/post.go b/git/post.go new file mode 100644 index 00000000..ffa7a460 --- /dev/null +++ b/git/post.go @@ -0,0 +1,15 @@ +package git + +import ( + "net/http" + + "github.com/hacdias/caddy-hugo/config" +) + +// POST handles the POST method on GIT page which is only an API. +func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) { + + w.Header().Set("Content-Type", "application/json") + w.Write([]byte("{}")) + return http.StatusOK, nil +} diff --git a/hugo.go b/hugo.go index 79ba7c72..754a40fe 100644 --- a/hugo.go +++ b/hugo.go @@ -18,6 +18,7 @@ import ( "github.com/hacdias/caddy-hugo/browse" "github.com/hacdias/caddy-hugo/config" "github.com/hacdias/caddy-hugo/editor" + "github.com/hacdias/caddy-hugo/git" "github.com/hacdias/caddy-hugo/utils" "github.com/mholt/caddy/caddy/setup" "github.com/mholt/caddy/middleware" @@ -135,6 +136,11 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error code, err = editor.ServeHTTP(w, r, h.Config) } + // Git API + if page == "edit" { + code, err = git.ServeHTTP(w, r, h.Config) + } + // Whenever the header "X-Regenerate" is true, the website should be // regenerated. Used in edit and settings, for example. if r.Header.Get("X-Regenerate") == "true" {