templates *do* like me after all

This commit is contained in:
kageru 2018-11-04 21:13:04 +01:00
parent 07d3839aa2
commit f5534b62ff
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
3 changed files with 5 additions and 13 deletions

View File

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

View File

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

View File

@ -5,5 +5,5 @@ else
msg="$1" msg="$1"
fi 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