small pixel drawing of a pufferfish nshc-form

Revise first draft
j3s j3s@c3f.net
Tue, 09 Jun 2020 22:12:23 -0500
commit

0e8a4e487c7689747f54822240655ff10d4c3f5f

parent

cc2cc42f261becc5ffd5fd3ea5787c0657a7a8d4

1 files changed, 25 insertions(+), 3 deletions(-)

jump to
M main.gomain.go

@@ -1,9 +1,31 @@

package main import ( - "fmt" + "html/template" + "log" + "net/http" ) -func main(){ - fmt.Println("Hello, world!") +func main() { + http.HandleFunc("/", rootHandler) + + log.Fatal(http.ListenAndServe(":8080", nil)) +} + +func rootHandler(w http.ResponseWriter, r *http.Request) { + render(w, "templates/form.html", nil) +} + +func render(w http.ResponseWriter, filename string, data interface{}) { + tmpl, err := template.ParseFiles(filename) + + if err != nil { + log.Println(err) + http.Error(w, "Sorry, something went wrong", http.StatusInternalServerError) + } + + if err := tmpl.Execute(w, data); err != nil { + log.Println(err) + http.Error(w, "Sorry, something went wrong", http.StatusInternalServerError) + } }