From 46225ea53a2c5f82ad2d02bff2e08d756eab9fc1 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Thu, 21 Aug 2014 01:04:35 +0200 Subject: [PATCH] Fixes html debug mode --- gin.go | 30 +++++++++++++++++------------- render/render.go | 6 +++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/gin.go b/gin.go index 8b6d17d5..0f4753e2 100644 --- a/gin.go +++ b/gin.go @@ -82,22 +82,26 @@ func Default() *Engine { } func (engine *Engine) LoadHTMLGlob(pattern string) { - templ := template.Must(template.ParseGlob(pattern)) - engine.SetHTMLTemplate(templ) -} - -func (engine *Engine) LoadHTMLFiles(files ...string) { - templ := template.Must(template.ParseFiles(files...)) - engine.SetHTMLTemplate(templ) -} - -func (engine *Engine) SetHTMLTemplate(templ *template.Template) { if gin_mode == debugCode { engine.HTMLRender = render.HTMLDebug } else { - engine.HTMLRender = render.HTMLRender{ - Template: templ, - } + templ := template.Must(template.ParseGlob(pattern)) + engine.SetHTMLTemplate(templ) + } +} + +func (engine *Engine) LoadHTMLFiles(files ...string) { + if gin_mode == debugCode { + engine.HTMLRender = render.HTMLDebug + } else { + templ := template.Must(template.ParseFiles(files...)) + engine.SetHTMLTemplate(templ) + } +} + +func (engine *Engine) SetHTMLTemplate(templ *template.Template) { + engine.HTMLRender = render.HTMLRender{ + Template: templ, } } diff --git a/render/render.go b/render/render.go index 57a59fe1..bc982a30 100644 --- a/render/render.go +++ b/render/render.go @@ -82,7 +82,11 @@ func (_ htmlDebugRender) Render(w http.ResponseWriter, code int, data ...interfa writeHeader(w, code, "text/html") file := data[0].(string) obj := data[1] - return template.New(file).Execute(w, obj) + t, err := template.ParseFiles(file) + if err != nil { + return err + } + return t.ExecuteTemplate(w, file, obj) } func (html HTMLRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {