templates *do* like me after all

dev
kageru 4 years ago
parent 07d3839aa2
commit f5534b62ff
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

@ -8,7 +8,6 @@ import (
"crypto/sha512"
"io"
"html/template"
"os"
)
type OutputFormatter struct {
@ -27,11 +26,7 @@ func startServer() {
}
func get(w http.ResponseWriter, r *http.Request) {
log.Println("rip?")
t := template.New("overview")
//t, err := t.ParseFiles("templates/overview.html")
t, err := t.Parse("{{.Author}} said: {{.Content}}")
t, err := template.ParseFiles("templates/overview.html")
if err != nil {
log.Panic(err)
@ -44,11 +39,8 @@ func get(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(post.Content))
}
*/
//results := readBlogpostsFromDB()
//t.Execute(w, OutputFormatter{Author: results[0].Author, Content: results[0].Content})
t.Execute(w, "asdasd")
t.Execute(os.Stdout, "asdasd")
//err = t.Execute(os.Stdout, OutputFormatter{Author: results[0].Author, Content: results[0].Content})
results := readBlogpostsFromDB()
err = t.ExecuteTemplate(w, "overview.html", OutputFormatter{Author: results[0].Author, Content: results[0].Content})
log.Println(err)
}

@ -1,7 +1,7 @@
<html>
<body style="background-color: #333; color: #ccc;">
<div id="content" style="width: 70%; margin: auto; padding-top: 10%;">
{{.}}
{{.Author}} said: {{.Content}}
</div>
</body>
</html>

@ -5,5 +5,5 @@ else
msg="$1"
fi
curl localhost:12345/add -d "{\"content\": \"$msg\", \"Title\": \"title\", \"Secret\": \"asdf\", \"author\": \"me\"}" -H "Content-Type: application/json" -v
curl localhost:12345/add -d "{\"content\": \"$msg\", \"Title\": \"title\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v

Loading…
Cancel
Save