diff --git a/server.go b/server.go index 95bc337..cce9826 100644 --- a/server.go +++ b/server.go @@ -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) } diff --git a/templates/overview.html b/templates/overview.html index 9b18fe4..183bede 100644 --- a/templates/overview.html +++ b/templates/overview.html @@ -1,7 +1,7 @@
- {{.}} + {{.Author}} said: {{.Content}}
diff --git a/test.sh b/test.sh index 92cc81f..ca122d8 100755 --- a/test.sh +++ b/test.sh @@ -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