filebrowser/edit/edit.go

41 lines
632 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
)
2015-09-13 11:14:18 +00:00
type editPage struct {
Var1 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
}
editInfo := new(editPage)
editInfo.Var1 = string(file)
2015-09-12 21:18:29 +00:00
2015-09-13 11:14:18 +00:00
page := new(page.Info)
page.Title = "Edit"
page.Body = editInfo
return page.Render("edit", w)
2015-09-12 19:02:26 +00:00
}
return 200, nil
}