From c4c64d0202ee4afa61ebbef7e9cc41938a6f9dff Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 21 May 2022 21:02:15 +0200 Subject: [PATCH] Add output buffering for rendered pages --- cmd/boardvoting/handlers.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/boardvoting/handlers.go b/cmd/boardvoting/handlers.go index 5530672..9459e1d 100644 --- a/cmd/boardvoting/handlers.go +++ b/cmd/boardvoting/handlers.go @@ -18,6 +18,7 @@ limitations under the License. package main import ( + "bytes" "fmt" "html/template" "io/fs" @@ -78,12 +79,18 @@ func (app *application) render(w http.ResponseWriter, status int, page string, d return } - w.WriteHeader(status) + buf := new(bytes.Buffer) - err := ts.ExecuteTemplate(w, "base", data) + err := ts.ExecuteTemplate(buf, "base", data) if err != nil { app.serverError(w, err) + + return } + + w.WriteHeader(status) + + _, _ = buf.WriteTo(w) } type motionListTemplateData struct {