docs and simplify

pull/48/head
Henrique Dias 2016-02-14 10:20:47 +00:00
parent 4a6c53a12b
commit 2414f2edec
5 changed files with 10 additions and 9 deletions

View File

@ -8,9 +8,9 @@ import (
"github.com/hacdias/caddy-hugo/config"
)
// 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.
// 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.
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Removes the page main path from the URL
r.URL.Path = strings.Replace(r.URL.Path, "/admin/browse", "", 1)

View File

@ -8,7 +8,7 @@ import (
"github.com/hacdias/caddy-hugo/config"
)
// DELETE handles the DELETE method on browse page
// DELETE handles the delete requests on browse pages
func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Remove both beginning and trailing slashes
path := r.URL.Path

View File

@ -10,7 +10,8 @@ import (
"github.com/mholt/caddy/middleware/browse"
)
// GET handles the GET method on browse page
// GET handles the GET method on browse page and shows the files listing Using
// the Browse Caddy middleware.
func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
functions := template.FuncMap{
"CanBeEdited": utils.CanBeEdited,

View File

@ -14,7 +14,8 @@ import (
"github.com/hacdias/caddy-hugo/utils"
)
// POST handles the POST method on browse page
// POST handles the POST method on browse page. It's used to create new files,
// folders and upload content.
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
// Remove prefix slash
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")

View File

@ -40,9 +40,8 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
new = strings.TrimSuffix(new, "/")
new = c.Path + new
err := os.Rename(old, new)
if err != nil {
// Renames the file/folder
if err := os.Rename(old, new); err != nil {
return 500, err
}