templates don’t like me

This commit is contained in:
kageru 2018-11-04 19:58:34 +01:00
parent f7b775cb38
commit be5b3f371b
4 changed files with 36 additions and 0 deletions

BIN
content Normal file

Binary file not shown.

BIN
miniblog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

View File

@ -7,8 +7,19 @@ import (
"encoding/hex"
"crypto/sha512"
"io"
"html/template"
"os"
)
type OutputFormatter struct {
Author string
Content string
}
type Wrapper struct {
Post OutputFormatter
}
func startServer() {
http.HandleFunc("/", get)
http.HandleFunc("/add", post)
@ -16,11 +27,29 @@ 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}}")
if err != nil {
log.Panic(err)
}
w.WriteHeader(http.StatusOK)
/*
w.Write([]byte("response:\n"))
for _, post := range readBlogpostsFromDB() {
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})
log.Println(err)
}
func post(w http.ResponseWriter, r *http.Request) {

7
templates/overview.html Normal file
View File

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