Blame view

go/src/themaru/vendor/github.com/gin-gonic/gin/debug.go 2.68 KB
476d2547e   김태훈   태마루 시스템 설정 / 업데이트...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  // 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 (
  	"bytes"
  	"fmt"
  	"html/template"
  	"os"
  	"runtime"
  	"strconv"
  	"strings"
  )
  
  const ginSupportMinGoVer = 8
  
  // IsDebugging returns true if the framework is running in debug mode.
  // Use SetMode(gin.ReleaseMode) to disable debug mode.
  func IsDebugging() bool {
  	return ginMode == debugCode
  }
  
  // DebugPrintRouteFunc indicates debug log output format.
  var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
  
  func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
  	if IsDebugging() {
  		nuHandlers := len(handlers)
  		handlerName := nameOfFunction(handlers.Last())
  		if DebugPrintRouteFunc == nil {
  			debugPrint("%-6s %-25s --> %s (%d handlers)
  ", httpMethod, absolutePath, handlerName, nuHandlers)
  		} else {
  			DebugPrintRouteFunc(httpMethod, absolutePath, handlerName, nuHandlers)
  		}
  	}
  }
  
  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("
  ")
  		}
  		debugPrint("Loaded HTML Templates (%d): 
  %s
  ", len(tmpl.Templates()), buf.String())
  	}
  }
  
  func debugPrint(format string, values ...interface{}) {
  	if IsDebugging() {
  		if !strings.HasSuffix(format, "
  ") {
  			format += "
  "
  		}
  		fmt.Fprintf(os.Stderr, "[GIN-debug] "+format, values...)
  	}
  }
  
  func getMinVer(v string) (uint64, error) {
  	first := strings.IndexByte(v, '.')
  	last := strings.LastIndexByte(v, '.')
  	if first == last {
  		return strconv.ParseUint(v[first+1:], 10, 64)
  	}
  	return strconv.ParseUint(v[first+1:last], 10, 64)
  }
  
  func debugPrintWARNINGDefault() {
  	if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {
  		debugPrint(`[WARNING] Now Gin requires Go 1.8 or later and Go 1.9 will be required soon.
  
  `)
  	}
  	debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
  
  `)
  }
  
  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
  
  `)
  }
  
  func debugPrintError(err error) {
  	if err != nil {
  		debugPrint("[ERROR] %v
  ", err)
  	}
  }