just a little testing
crispy-caesus 114518720+crispy-caesus@users.noreply.github.com
Fri, 01 Nov 2024 13:11:12 +0100
1 files changed,
13 insertions(+),
15 deletions(-)
jump to
M
index.go
→
index.go
@@ -1,33 +1,31 @@
package main import ( - "log" - "net/http" - "html/template" + "html/template" + "log" + "net/http" ) type Page struct { - Title string - Body []byte + Title string + Body []byte } var templates = template.Must(template.ParseFiles("index.html")) func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) { - err := templates.ExecuteTemplate(w, tmpl+".html", p) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } + err := templates.ExecuteTemplate(w, tmpl+".html", p) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } } func viewHandler(w http.ResponseWriter, r *http.Request) { - p := &Page{Title: "index"} - renderTemplate(w, "index", p) + p := &Page{Title: "index"} + renderTemplate(w, "index", p) } - func main() { - http.HandleFunc("/", viewHandler) - log.Fatal(http.ListenAndServe(":8080", nil)) + http.HandleFunc("/", viewHandler) + log.Fatal(http.ListenAndServe(":8080", nil)) } -