1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00
woodpecker/vendor/github.com/gin-gonic/gin/debug.go

72 lines
1.8 KiB
Go
Raw Normal View History

2015-05-22 20:37:40 +02: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
import (
2015-09-30 03:21:17 +02:00
"bytes"
"html/template"
2015-05-22 20:37:40 +02:00
"log"
)
2015-09-30 03:21:17 +02:00
func init() {
log.SetFlags(0)
}
2015-05-22 20:37:40 +02:00
2015-09-30 03:21:17 +02:00
// IsDebugging returns true if the framework is running in debug mode.
// Use SetMode(gin.Release) to switch to disable the debug mode.
2015-05-22 20:37:40 +02:00
func IsDebugging() bool {
return ginMode == debugCode
}
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
if IsDebugging() {
nuHandlers := len(handlers)
2015-09-30 03:21:17 +02:00
handlerName := nameOfFunction(handlers.Last())
2016-03-07 21:23:49 +02:00
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
2015-05-22 20:37:40 +02:00
}
}
2015-09-30 03:21:17 +02:00
func debugPrintLoadTemplate(tmpl *template.Template) {
if IsDebugging() {
var buf bytes.Buffer
for _, tmpl := range tmpl.Templates() {
buf.WriteString("\t- ")
buf.WriteString(tmpl.Name())
buf.WriteString("\n")
}
debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
}
}
2015-05-22 20:37:40 +02:00
func debugPrint(format string, values ...interface{}) {
if IsDebugging() {
2015-09-30 03:21:17 +02:00
log.Printf("[GIN-debug] "+format, values...)
2015-05-22 20:37:40 +02:00
}
}
2015-09-30 03:21:17 +02:00
func debugPrintWARNINGNew() {
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 debugPrintWARNINGSetHTMLTemplate() {
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-22 20:37:40 +02:00
}
func debugPrintError(err error) {
if err != nil {
debugPrint("[ERROR] %v\n", err)
}
}