I want to make a hello world web app that will properly catch template error. So I need to buffer the response but don't know how to do it. I've put together this code. Is this the way to buffer a response in golang?
func get_handler(w http.ResponseWriter, r *http.Request) {
buf := new(bytes.Buffer)
err := templates.ExecuteTemplate(buf, "hello.html", nil)
if err != nil {
fmt.Println(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write([]byte(buf.String()))
}