From 00b279c66ba4b607912088886c759e121b49b7e4 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Fri, 12 Jun 2015 18:09:44 +0200 Subject: [PATCH] Adds SetHTMLTemplate() warning --- gin.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gin.go b/gin.go index eb6e8fc4..8130b88f 100644 --- a/gin.go +++ b/gin.go @@ -116,6 +116,14 @@ func (engine *Engine) LoadHTMLFiles(files ...string) { } func (engine *Engine) SetHTMLTemplate(templ *template.Template) { + if len(engine.trees) > 0 { + debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called +at initialization. ie. before any route is registered or the router is listening in a socket: + + router := gin.Default() + router.SetHTMLTemplate(template) // << good place +`) + } engine.HTMLRender = render.HTMLProduction{Template: templ} }