From 4cc2de6207f4128624cbdd16be30f64966c67c08 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Fri, 26 Jun 2015 16:08:55 +0200 Subject: [PATCH] Refactors warning messages --- debug.go | 12 +++++++++++- gin.go | 9 ++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/debug.go b/debug.go index e5b39cc2..2f4b1015 100644 --- a/debug.go +++ b/debug.go @@ -27,7 +27,7 @@ func debugPrint(format string, values ...interface{}) { } } -func debugPrintWARNING() { +func debugPrintWARNING_New() { debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production. - using env: export GIN_MODE=release - using code: gin.SetMode(gin.ReleaseMode) @@ -35,6 +35,16 @@ func debugPrintWARNING() { `) } +func debugPrintWARNING_SetHTMLTemplate() { + 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 + +`) +} + func debugPrintError(err error) { if err != nil { debugPrint("[ERROR] %v\n", err) diff --git a/gin.go b/gin.go index 295e18f4..7b0ede17 100644 --- a/gin.go +++ b/gin.go @@ -83,7 +83,7 @@ var _ RoutesInterface = &Engine{} // Returns a new blank Engine instance without any middleware attached. // The most basic configuration func New() *Engine { - debugPrintWARNING() + debugPrintWARNING_New() engine := &Engine{ RouterGroup: RouterGroup{ Handlers: nil, @@ -134,12 +134,7 @@ 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 -`) + debugPrintWARNING_SetHTMLTemplate() } engine.HTMLRender = render.HTMLProduction{Template: templ} }