-
Notifications
You must be signed in to change notification settings - Fork 52
/
debug.go
54 lines (48 loc) · 1.19 KB
/
debug.go
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
package znet
import (
"fmt"
"html/template"
"github.com/sohaha/zlsgo/zlog"
"github.com/sohaha/zlsgo/zstring"
)
func showRouteDebug(log *zlog.Logger, tf, method, path string) string {
mLen := zstring.Len(method)
var mtd string
min := 6
if mLen < min {
mtd = zstring.Pad(method, min, " ", 1)
} else {
mtd = zstring.Substr(method, 0, min)
}
switch method {
case "GET":
method = log.ColorTextWrap(zlog.ColorLightCyan, mtd)
case "POST":
method = log.ColorTextWrap(zlog.ColorLightBlue, mtd)
case "PUT":
method = log.ColorTextWrap(zlog.ColorLightGreen, mtd)
case "DELETE":
method = log.ColorTextWrap(zlog.ColorRed, mtd)
case "Any":
method = log.ColorTextWrap(zlog.ColorLightMagenta, mtd)
case "OPTIONS":
method = log.ColorTextWrap(zlog.ColorLightMagenta, mtd)
default:
method = log.ColorTextWrap(zlog.ColorDefault, mtd)
}
return fmt.Sprintf(tf, method, path)
}
func templatesDebug(t *template.Template) {
l := len(t.Templates())
buf := zstring.Buffer(l)
for _, t := range t.Templates() {
n := t.Name()
if n == "" {
continue
}
buf.WriteString("\t - ")
buf.WriteString(n)
buf.WriteString("\n")
}
Log.Debugf("Loaded HTML Templates (%d): \n%s", l, buf.String())
}