-
Notifications
You must be signed in to change notification settings - Fork 0
/
printStat.go
50 lines (45 loc) · 871 Bytes
/
printStat.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
package main
import (
"fmt"
"net/http"
"strings"
"time"
)
// print the pretty output ^_^
func printStat(r *http.Request, dur time.Time, method string) {
reset := "\033[0m"
// default is green maing cache
methodBg := "\033[42m"
// Black
methodFg := "\033[0;30m"
if method == "comp" {
// yellow
methodBg = "\033[43m"
} else if method == "err" {
// red
methodBg = "\033[41m"
} else if method == "file" {
// cyan
methodBg = "\033[46m"
}
fmt.Printf("[stat] %s | %13s |%s%s %5s %s| %15s | %s | \"%s\"\n",
time.Now().Format("2006/01/02 - 03:04:05 PM"),
time.Since(dur),
methodFg,
methodBg,
method,
reset,
strings.Split(r.RemoteAddr, ":")[0],
r.Method,
r.URL.Path,
)
}
/*
// laaaaaaaaaaaaaaaa
func colorableStdout() io.Writer {
if runtime.GOOS == "windows" {
return colorable.NewColorableStdout()
}
return os.Stdout
}
*/