simplify some stuff

This commit is contained in:
Henrique Dias
2016-03-12 09:52:04 +00:00
parent 3301b60485
commit d41e4cc047
9 changed files with 33 additions and 54 deletions

View File

@@ -7,18 +7,17 @@ import (
"os"
"strings"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/server"
)
// PUT handles the HTTP PUT request for all /admin/browse related requests.
// Renames a file and/or a folder.
func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
func PUT(w http.ResponseWriter, r *http.Request) (int, error) {
// Remove both beginning and trailing slashes
old := r.URL.Path
old = strings.TrimPrefix(old, "/")
old = strings.TrimSuffix(old, "/")
old = c.Path + old
old = conf.Path + old
// Get the JSON information sent using a buffer
buffer := new(bytes.Buffer)
@@ -40,7 +39,7 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
new := info["filename"].(string)
new = strings.TrimPrefix(new, "/")
new = strings.TrimSuffix(new, "/")
new = c.Path + new
new = conf.Path + new
// Renames the file/folder
if err := os.Rename(old, new); err != nil {