2015-09-18 15:49:53 +00:00
|
|
|
package editor
|
|
|
|
|
|
|
|
import (
|
2015-10-16 19:03:59 +00:00
|
|
|
"errors"
|
2015-09-18 15:49:53 +00:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2015-10-18 14:10:32 +00:00
|
|
|
"github.com/hacdias/caddy-hugo/config"
|
2015-09-18 15:49:53 +00:00
|
|
|
)
|
|
|
|
|
2015-09-20 08:15:21 +00:00
|
|
|
// ServeHTTP serves the editor page
|
|
|
|
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
2015-09-18 15:49:53 +00:00
|
|
|
filename := strings.Replace(r.URL.Path, "/admin/edit/", "", 1)
|
2015-09-30 21:03:28 +00:00
|
|
|
filename = c.Path + filename
|
2015-09-18 15:49:53 +00:00
|
|
|
|
2015-09-26 21:02:49 +00:00
|
|
|
switch r.Method {
|
|
|
|
case "POST":
|
|
|
|
return POST(w, r, c, filename)
|
|
|
|
case "GET":
|
|
|
|
return GET(w, r, c, filename)
|
2015-09-19 13:25:35 +00:00
|
|
|
default:
|
2015-10-16 19:03:59 +00:00
|
|
|
return 400, errors.New("Invalid method.")
|
2015-09-19 13:25:35 +00:00
|
|
|
}
|
2015-09-19 13:47:59 +00:00
|
|
|
}
|