OSDN Git Service

feat(warder): add warder backbone (#181)
[bytom/vapor.git] / vendor / github.com / gin-gonic / gin / debug.go
1 // Copyright 2014 Manu Martinez-Almeida.  All rights reserved.
2 // Use of this source code is governed by a MIT style
3 // license that can be found in the LICENSE file.
4
5 package gin
6
7 import (
8         "bytes"
9         "html/template"
10         "log"
11 )
12
13 func init() {
14         log.SetFlags(0)
15 }
16
17 // IsDebugging returns true if the framework is running in debug mode.
18 // Use SetMode(gin.ReleaseMode) to disable debug mode.
19 func IsDebugging() bool {
20         return ginMode == debugCode
21 }
22
23 func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
24         if IsDebugging() {
25                 nuHandlers := len(handlers)
26                 handlerName := nameOfFunction(handlers.Last())
27                 debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
28         }
29 }
30
31 func debugPrintLoadTemplate(tmpl *template.Template) {
32         if IsDebugging() {
33                 var buf bytes.Buffer
34                 for _, tmpl := range tmpl.Templates() {
35                         buf.WriteString("\t- ")
36                         buf.WriteString(tmpl.Name())
37                         buf.WriteString("\n")
38                 }
39                 debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
40         }
41 }
42
43 func debugPrint(format string, values ...interface{}) {
44         if IsDebugging() {
45                 log.Printf("[GIN-debug] "+format, values...)
46         }
47 }
48
49 func debugPrintWARNINGDefault() {
50         debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.
51
52 `)
53         debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
54
55 `)
56 }
57
58 func debugPrintWARNINGNew() {
59         debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
60  - using env:   export GIN_MODE=release
61  - using code:  gin.SetMode(gin.ReleaseMode)
62
63 `)
64 }
65
66 func debugPrintWARNINGSetHTMLTemplate() {
67         debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called
68 at initialization. ie. before any route is registered or the router is listening in a socket:
69
70         router := gin.Default()
71         router.SetHTMLTemplate(template) // << good place
72
73 `)
74 }
75
76 func debugPrintError(err error) {
77         if err != nil {
78                 debugPrint("[ERROR] %v\n", err)
79         }
80 }