mirror of https://github.com/gin-gonic/gin.git
Refactors warning messages
This commit is contained in:
parent
9268afb15d
commit
4cc2de6207
12
debug.go
12
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.
|
debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
|
||||||
- using env: export GIN_MODE=release
|
- using env: export GIN_MODE=release
|
||||||
- using code: gin.SetMode(gin.ReleaseMode)
|
- 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) {
|
func debugPrintError(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debugPrint("[ERROR] %v\n", err)
|
debugPrint("[ERROR] %v\n", err)
|
||||||
|
|
9
gin.go
9
gin.go
|
@ -83,7 +83,7 @@ var _ RoutesInterface = &Engine{}
|
||||||
// Returns a new blank Engine instance without any middleware attached.
|
// Returns a new blank Engine instance without any middleware attached.
|
||||||
// The most basic configuration
|
// The most basic configuration
|
||||||
func New() *Engine {
|
func New() *Engine {
|
||||||
debugPrintWARNING()
|
debugPrintWARNING_New()
|
||||||
engine := &Engine{
|
engine := &Engine{
|
||||||
RouterGroup: RouterGroup{
|
RouterGroup: RouterGroup{
|
||||||
Handlers: nil,
|
Handlers: nil,
|
||||||
|
@ -134,12 +134,7 @@ 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 {
|
if len(engine.trees) > 0 {
|
||||||
debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called
|
debugPrintWARNING_SetHTMLTemplate()
|
||||||
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}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue