filebrowser/edit/edit.go

41 lines
609 B
Go
Raw Normal View History

2015-09-12 19:02:26 +00:00
package edit
import (
"io/ioutil"
"net/http"
"os"
2015-09-13 11:14:18 +00:00
"github.com/hacdias/caddy-hugo/page"
2015-09-12 19:02:26 +00:00
)
type info struct {
File string
2015-09-12 19:02:26 +00:00
}
// Execute sth
func Execute(w http.ResponseWriter, r *http.Request, file string) (int, error) {
if r.Method == "POST" {
// it's saving the post
} else {
if _, err := os.Stat(file); os.IsNotExist(err) {
return 404, nil
}
2015-09-13 11:14:18 +00:00
file, err := ioutil.ReadFile(file)
if err != nil {
return 500, err
}
inf := new(info)
inf.File = string(file)
2015-09-12 21:18:29 +00:00
page := new(page.Page)
2015-09-13 11:14:18 +00:00
page.Title = "Edit"
page.Body = inf
2015-09-13 11:14:18 +00:00
return page.Render("edit", w)
2015-09-12 19:02:26 +00:00
}
return 200, nil
}