filebrowser/routes/browse/browse.go

39 lines
852 B
Go
Raw Normal View History

package browse
import (
2015-10-16 19:03:59 +00:00
"errors"
"net/http"
2015-09-17 16:41:31 +00:00
"strings"
2015-10-18 14:10:32 +00:00
"github.com/hacdias/caddy-hugo/config"
)
2016-03-12 09:52:04 +00:00
var conf *config.Config
2016-03-12 13:03:31 +00:00
type response struct {
Message string `json:"message"`
Location string `json:"location"`
}
2016-02-14 10:20:47 +00:00
// ServeHTTP is used to serve the content of Browse page using Browse middleware
// from Caddy. It handles the requests for DELETE, POST, GET and PUT related to
// /browse interface.
2015-09-20 08:15:21 +00:00
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
2016-03-12 09:52:04 +00:00
conf = c
2015-09-20 08:15:21 +00:00
// Removes the page main path from the URL
2015-09-17 16:41:31 +00:00
r.URL.Path = strings.Replace(r.URL.Path, "/admin/browse", "", 1)
2015-09-20 19:42:22 +00:00
switch r.Method {
case "DELETE":
2016-03-12 09:52:04 +00:00
return DELETE(w, r)
2015-09-20 19:42:22 +00:00
case "POST":
2016-03-12 09:52:04 +00:00
return POST(w, r)
2015-09-20 19:42:22 +00:00
case "GET":
2016-03-12 09:52:04 +00:00
return GET(w, r)
2016-02-06 17:18:30 +00:00
case "PUT":
2016-03-12 09:52:04 +00:00
return PUT(w, r)
2015-09-20 19:42:22 +00:00
default:
2016-03-06 14:23:37 +00:00
return http.StatusMethodNotAllowed, errors.New("Invalid method.")
2015-09-17 16:41:31 +00:00
}
2015-09-20 19:42:22 +00:00
}