-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfield.go
93 lines (82 loc) · 1.48 KB
/
field.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
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
package abstractlogger
type Field struct {
kind FieldKind
key string
stringValue string
stringsValue []string
intValue int64
byteValue []byte
interfaceValue interface{}
errorValue error
}
type FieldKind int
const (
StringField FieldKind = iota + 1
StringsField
IntField
BoolField
ByteStringField
InterfaceField
ErrorField
NamedErrorField
)
func Any(key string, value interface{}) Field {
return Field{
kind: InterfaceField,
key: key,
interfaceValue: value,
}
}
func Error(err error) Field {
return Field{
kind: ErrorField,
key: "error",
errorValue: err,
}
}
func NamedError(key string, err error) Field {
return Field{
kind: NamedErrorField,
key: key,
errorValue: err,
}
}
func String(key, value string) Field {
return Field{
kind: StringField,
key: key,
stringValue: value,
}
}
func Strings(key string, value []string) Field {
return Field{
key: key,
kind: StringsField,
stringsValue: value,
}
}
func Int(key string, value int) Field {
return Field{
kind: IntField,
key: key,
intValue: int64(value),
}
}
func Bool(key string, value bool) Field {
var integer int64
if value {
integer = 1
}
return Field{
kind: BoolField,
key: key,
intValue: integer,
}
}
func ByteString(key string, value []byte) Field {
return Field{
kind: ByteStringField,
key: key,
byteValue: value,
}
}