-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathutil.go
48 lines (43 loc) · 995 Bytes
/
util.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
package gormzap
import (
"fmt"
"time"
"unicode"
)
func isPrintable(s string) bool {
for _, r := range s {
if !unicode.IsPrint(r) {
return false
}
}
return true
}
func getFormattedValues(values []interface{}) []string {
rawValues := values[4].([]interface{})
formattedValues := make([]string, 0, len(rawValues))
for _, value := range rawValues {
switch v := value.(type) {
case time.Time:
formattedValues = append(formattedValues, fmt.Sprint(v))
case []byte:
if str := string(v); isPrintable(str) {
formattedValues = append(formattedValues, fmt.Sprint(str))
} else {
formattedValues = append(formattedValues, "<binary>")
}
default:
str := "NULL"
if v != nil {
str = fmt.Sprint(v)
}
formattedValues = append(formattedValues, str)
}
}
return formattedValues
}
func getSource(values []interface{}) string {
return fmt.Sprint(values[1])
}
func getDuration(values []interface{}) time.Duration {
return values[2].(time.Duration)
}