Adds SetHTMLTemplate() warning

This commit is contained in:
Manu Mtz-Almeida 2015-06-12 18:09:44 +02:00
parent 4998bc2b2e
commit 00b279c66b
1 changed files with 8 additions and 0 deletions

8
gin.go
View File

@ -116,6 +116,14 @@ func (engine *Engine) LoadHTMLFiles(files ...string) {
} }
func (engine *Engine) SetHTMLTemplate(templ *template.Template) { 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} engine.HTMLRender = render.HTMLProduction{Template: templ}
} }