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

@@ -1,15 +1,12 @@
package browse
import (
"errors"
"net/http"
"strings"
"github.com/hacdias/caddy-hugo/config"
)
var conf *config.Config
type response struct {
Message string `json:"message"`
Location string `json:"location"`
@@ -19,20 +16,18 @@ type response struct {
// from Caddy. It handles the requests for DELETE, POST, GET and PUT related to
// /browse interface.
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
conf = c
// Removes the page main path from the URL
r.URL.Path = strings.Replace(r.URL.Path, c.Admin+"/browse", "", 1)
switch r.Method {
case "DELETE":
return DELETE(w, r)
return DELETE(w, r, c)
case "POST":
return POST(w, r, c)
case "GET":
return GET(w, r)
return GET(w, r, c)
case "PUT":
return PUT(w, r)
return PUT(w, r, c)
default:
return http.StatusMethodNotAllowed, errors.New("Invalid method.")
return http.StatusNotImplemented, nil
}
}