From 68aea511fa8a79c0ec719e6985d870544cf31618 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 22 Jun 2016 17:44:01 +0100 Subject: [PATCH] better error check --- page.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/page.go b/page.go index a65aa80a..5082c4da 100644 --- a/page.go +++ b/page.go @@ -1,6 +1,8 @@ package filemanager import ( + "bufio" + "bytes" "encoding/json" "html/template" "log" @@ -100,13 +102,16 @@ func (p *Page) AddTemplate(name string, assets AssetFunc, functions template.Fun // PrintAsHTML formats the page in HTML and executes the template func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) { - w.Header().Set("Content-Type", "text/html; charset=utf-8") - err := p.Tpl.Execute(w, p.Info) + var buffer bytes.Buffer + writer := bufio.NewWriter(&buffer) + err := p.Tpl.Execute(writer, p.Info) if err != nil { return http.StatusInternalServerError, err } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + buffer.WriteTo(w) return http.StatusOK, nil }