forked from gin-gonic/gin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
color.go
52 lines (48 loc) · 1.33 KB
/
color.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
// 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 middleware
var (
__colorGreen = string([]byte{27, 91, 57, 55, 59, 52, 50, 109})
__colorWhite = string([]byte{27, 91, 57, 48, 59, 52, 55, 109})
__colorYellow = string([]byte{27, 91, 57, 55, 59, 52, 51, 109})
__colorRed = string([]byte{27, 91, 57, 55, 59, 52, 49, 109})
__colorBlue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109})
__colorMagenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
__colorCyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109})
__colorReset = string([]byte{27, 91, 48, 109})
)
func colorForStatus(code int) string {
switch {
case code < 200:
return __colorRed
case code < 300: // [200, 300)
return __colorGreen
case code < 400: // [300, 400)
return __colorWhite
case code < 500: // [400, 500)
return __colorYellow
default: // >= 500
return __colorRed
}
}
func colorForMethod(method string) string {
switch method {
case "GET":
return __colorBlue
case "POST":
return __colorCyan
case "PUT":
return __colorYellow
case "DELETE":
return __colorRed
case "PATCH":
return __colorGreen
case "HEAD":
return __colorMagenta
case "OPTIONS":
return __colorWhite
default:
return __colorReset
}
}