-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfield.go
109 lines (92 loc) · 2.06 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package logx
import (
"errors"
"fmt"
)
type FieldType int
const (
nnknownType FieldType = iota
boolType
boolSliceType
intType
intSliceType
int64Type
int64SliceType
float64Type
float64SliceType
stringType
stringSliceType
stringerType
anyType
errType
)
type Field struct {
Key string
Type FieldType
Bool bool
Bools []bool
Integer int
Integers []int
String string
Float64 float64
Integer64 int64
Integer64s []int64
Strings []string
Float64s []float64
Any interface{}
}
// Bool
func Bool(key string, val bool) Field {
return Field{Key: key, Type: boolType, Bool: val}
}
// BoolSlice
func BoolSlice(key string, val []bool) Field {
return Field{Key: key, Type: boolSliceType, Bools: val}
}
// Int
func Int(key string, val int) Field {
return Field{Key: key, Type: intType, Integer: val}
}
// IntSlice
func IntSlice(key string, val []int) Field {
return Field{Key: key, Type: intSliceType, Integers: val}
}
// Int64
func Int64(key string, val int64) Field {
return Field{Key: key, Type: int64Type, Integer64: val}
}
// Int64Slice
func Int64Slice(key string, val []int64) Field {
return Field{Key: key, Type: int64SliceType, Integer64s: val}
}
// Float64
func Float64(key string, val float64) Field {
return Field{Key: key, Type: float64Type, Float64: val}
}
// Float64Slice
func Float64Slice(key string, val []float64) Field {
return Field{Key: key, Type: float64SliceType, Float64s: val}
}
// String
func String(key string, val string) Field {
return Field{Key: key, Type: stringType, String: val}
}
// StringSlice
func StringSlice(key string, val []string) Field {
return Field{Key: key, Type: stringSliceType, Strings: val}
}
// Stringer
func Stringer(key string, val fmt.Stringer) Field {
return Field{Key: key, Type: stringerType, String: val.String()}
}
// Any
func Any(key string, val interface{}) Field {
return Field{Key: key, Type: anyType, Any: val}
}
// Err
func Err(err error) Field {
if err == nil {
err = errors.New("nil")
}
return Field{Key: "error", Type: stringType, String: err.Error()}
}