From 2b3aa5173898ed07d45c9a16994d3d259f368431 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Mon, 3 Aug 2015 17:28:12 +0200 Subject: [PATCH] Template debugging --- debug.go | 18 +++++++++++++++++- gin.go | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/debug.go b/debug.go index bff86e10..0836fc56 100644 --- a/debug.go +++ b/debug.go @@ -4,7 +4,11 @@ package gin -import "log" +import ( + "bytes" + "html/template" + "log" +) func init() { log.SetFlags(0) @@ -24,6 +28,18 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) { } } +func debugPrintLoadTemplate(tmpl *template.Template) { + if IsDebugging() { + var buf bytes.Buffer + for _, tmpl := range tmpl.Templates() { + buf.WriteString("\t- ") + buf.WriteString(tmpl.Name()) + buf.WriteString("\n") + } + debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String()) + } +} + func debugPrint(format string, values ...interface{}) { if IsDebugging() { log.Printf("[GIN-debug] "+format, values...) diff --git a/gin.go b/gin.go index 54b4e59f..c9d38d68 100644 --- a/gin.go +++ b/gin.go @@ -123,6 +123,7 @@ func (engine *Engine) allocateContext() *Context { func (engine *Engine) LoadHTMLGlob(pattern string) { if IsDebugging() { + debugPrintLoadTemplate(template.Must(template.ParseGlob(pattern))) engine.HTMLRender = render.HTMLDebug{Glob: pattern} } else { templ := template.Must(template.ParseGlob(pattern))