2015-03-23 05:03:12 +00:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gin
|
|
|
|
|
2015-05-23 23:00:17 +00:00
|
|
|
import "log"
|
2015-03-23 05:03:12 +00:00
|
|
|
|
2015-05-23 23:00:17 +00:00
|
|
|
func init() {
|
|
|
|
log.SetFlags(0)
|
|
|
|
}
|
2015-07-02 18:24:54 +00:00
|
|
|
|
|
|
|
// IsDebugging returns true if the framework is running in debug mode.
|
|
|
|
// Use SetMode(gin.Release) to switch to disable the debug mode.
|
2015-03-23 05:03:12 +00:00
|
|
|
func IsDebugging() bool {
|
2015-04-07 10:27:23 +00:00
|
|
|
return ginMode == debugCode
|
2015-03-23 05:03:12 +00:00
|
|
|
}
|
|
|
|
|
2015-05-09 01:34:43 +00:00
|
|
|
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
2015-03-23 05:03:12 +00:00
|
|
|
if IsDebugging() {
|
|
|
|
nuHandlers := len(handlers)
|
2015-06-07 11:49:36 +00:00
|
|
|
handlerName := nameOfFunction(handlers.Last())
|
2015-03-23 05:03:12 +00:00
|
|
|
debugPrint("%-5s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func debugPrint(format string, values ...interface{}) {
|
|
|
|
if IsDebugging() {
|
2015-05-23 23:00:17 +00:00
|
|
|
log.Printf("[GIN-debug] "+format, values...)
|
2015-03-23 05:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-09 01:34:43 +00:00
|
|
|
|
2015-07-02 18:24:54 +00:00
|
|
|
func debugPrintWARNINGNew() {
|
2015-05-23 23:21:23 +00:00
|
|
|
debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
|
|
|
|
- using env: export GIN_MODE=release
|
|
|
|
- using code: gin.SetMode(gin.ReleaseMode)
|
|
|
|
|
|
|
|
`)
|
2015-05-09 01:34:43 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 18:24:54 +00:00
|
|
|
func debugPrintWARNINGSetHTMLTemplate() {
|
2015-06-26 14:08:55 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2015-05-09 01:34:43 +00:00
|
|
|
func debugPrintError(err error) {
|
|
|
|
if err != nil {
|
|
|
|
debugPrint("[ERROR] %v\n", err)
|
|
|
|
}
|
|
|
|
}
|