-
Notifications
You must be signed in to change notification settings - Fork 2
/
field.go
113 lines (92 loc) · 2.26 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
110
111
112
113
package metrics
// Field represents a giving map of values associated with a giving field value.
type Field map[string]interface{}
// GetBool collects the string value of a key if it exists.
func (p Field) GetBool(key string) (bool, bool) {
val, found := p.Get(key)
if !found {
return false, false
}
value, ok := val.(bool)
return value, ok
}
// GetFloat64 collects the string value of a key if it exists.
func (p Field) GetFloat64(key string) (float64, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(float64)
return value, ok
}
// GetFloat32 collects the string value of a key if it exists.
func (p Field) GetFloat32(key string) (float32, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(float32)
return value, ok
}
// GetInt8 collects the string value of a key if it exists.
func (p Field) GetInt8(key string) (int8, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(int8)
return value, ok
}
// GetInt16 collects the string value of a key if it exists.
func (p Field) GetInt16(key string) (int16, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(int16)
return value, ok
}
// GetInt64 collects the string value of a key if it exists.
func (p Field) GetInt64(key string) (int64, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(int64)
return value, ok
}
// GetInt32 collects the string value of a key if it exists.
func (p Field) GetInt32(key string) (int32, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(int32)
return value, ok
}
// GetInt collects the string value of a key if it exists.
func (p Field) GetInt(key string) (int, bool) {
val, found := p.Get(key)
if !found {
return 0, false
}
value, ok := val.(int)
return value, ok
}
// GetString collects the string value of a key if it exists.
func (p Field) GetString(key string) (string, bool) {
val, found := p.Get(key)
if !found {
return "", false
}
value, ok := val.(string)
return value, ok
}
// Get collects the value of a key if it exists.
func (p Field) Get(key string) (value interface{}, found bool) {
if p == nil {
return
}
val, ok := p[key]
return val, ok
}