remove dangerous global variables

This commit is contained in:
Henrique Dias
2016-06-16 17:01:41 +01:00
parent 48878cc3b5
commit af2785e510
11 changed files with 66 additions and 82 deletions

View File

@@ -7,17 +7,18 @@ 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) (int, error) {
func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Remove both beginning and trailing slashes
old := r.URL.Path
old = strings.TrimPrefix(old, "/")
old = strings.TrimSuffix(old, "/")
old = conf.Path + old
old = c.Path + old
// Get the JSON information sent using a buffer
buffer := new(bytes.Buffer)
@@ -37,7 +38,7 @@ func PUT(w http.ResponseWriter, r *http.Request) (int, error) {
new := info["filename"].(string)
new = strings.TrimPrefix(new, "/")
new = strings.TrimSuffix(new, "/")
new = conf.Path + new
new = c.Path + new
// Renames the file/folder
if err := os.Rename(old, new); err != nil {