Skip to content

Commit

Permalink
Refactors warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jun 26, 2015
1 parent 9268afb commit 4cc2de6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 11 additions & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ 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)
`)
}

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)
Expand Down
9 changes: 2 additions & 7 deletions gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
}
Expand Down

0 comments on commit 4cc2de6

Please sign in to comment.