best routing, static files embedding

This commit is contained in:
Henrique Dias
2015-09-13 12:14:18 +01:00
parent 6cdc145809
commit 8eeeb3870f
13 changed files with 921 additions and 67 deletions

View File

@@ -4,9 +4,12 @@ import (
"io/ioutil"
"net/http"
"os"
"github.com/hacdias/caddy-hugo/page"
)
type Page struct {
type editPage struct {
Var1 string
}
// Execute sth
@@ -14,15 +17,23 @@ func Execute(w http.ResponseWriter, r *http.Request, file string) (int, error) {
if r.Method == "POST" {
// it's saving the post
} else {
// check if the file exists
if _, err := os.Stat(file); os.IsNotExist(err) {
return 404, nil
}
file, _ := ioutil.ReadFile(file)
file, err := ioutil.ReadFile(file)
// render the template here
w.Write([]byte(string(file)))
if err != nil {
return 500, err
}
editInfo := new(editPage)
editInfo.Var1 = string(file)
page := new(page.Info)
page.Title = "Edit"
page.Body = editInfo
return page.Render("edit", w)
}
return 200, nil