templates don’t like me
This commit is contained in:
parent
f7b775cb38
commit
be5b3f371b
Binary file not shown.
After Width: | Height: | Size: 250 KiB |
29
server.go
29
server.go
|
@ -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) {
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue
Block a user