@@ -42,11 +42,14 @@ func (k *ValueKey) Description() string { return k.description }
42
42
// Get can be used to get a tag for the key from a TagMap.
43
43
func (k * ValueKey ) Get (tags TagMap ) interface {} {
44
44
if t := tags .Find (k ); t .Valid () {
45
- return t . Value
45
+ return k . From ( t )
46
46
}
47
47
return nil
48
48
}
49
49
50
+ // From can be used to get a value from a Tag.
51
+ func (k * ValueKey ) From (t Tag ) interface {} { return t .Value }
52
+
50
53
// Of creates a new Tag with this key and the supplied value.
51
54
func (k * ValueKey ) Of (value interface {}) Tag { return Tag {Key : k , Value : value } }
52
55
@@ -70,11 +73,14 @@ func (k *IntKey) Of(v int) Tag { return Tag{Key: k, Value: v} }
70
73
// Get can be used to get a tag for the key from a TagMap.
71
74
func (k * IntKey ) Get (tags TagMap ) int {
72
75
if t := tags .Find (k ); t .Valid () {
73
- return t . Value .( int )
76
+ return k . From ( t )
74
77
}
75
78
return 0
76
79
}
77
80
81
+ // From can be used to get a value from a Tag.
82
+ func (k * IntKey ) From (t Tag ) int { return t .Value .(int ) }
83
+
78
84
// Int8Key represents a key
79
85
type Int8Key struct {
80
86
name string
@@ -95,11 +101,14 @@ func (k *Int8Key) Of(v int8) Tag { return Tag{Key: k, Value: v} }
95
101
// Get can be used to get a tag for the key from a TagMap.
96
102
func (k * Int8Key ) Get (tags TagMap ) int8 {
97
103
if t := tags .Find (k ); t .Valid () {
98
- return t . Value .( int8 )
104
+ return k . From ( t )
99
105
}
100
106
return 0
101
107
}
102
108
109
+ // From can be used to get a value from a Tag.
110
+ func (k * Int8Key ) From (t Tag ) int8 { return t .Value .(int8 ) }
111
+
103
112
// Int16Key represents a key
104
113
type Int16Key struct {
105
114
name string
@@ -120,11 +129,14 @@ func (k *Int16Key) Of(v int16) Tag { return Tag{Key: k, Value: v} }
120
129
// Get can be used to get a tag for the key from a TagMap.
121
130
func (k * Int16Key ) Get (tags TagMap ) int16 {
122
131
if t := tags .Find (k ); t .Valid () {
123
- return t . Value .( int16 )
132
+ return k . From ( t )
124
133
}
125
134
return 0
126
135
}
127
136
137
+ // From can be used to get a value from a Tag.
138
+ func (k * Int16Key ) From (t Tag ) int16 { return t .Value .(int16 ) }
139
+
128
140
// Int32Key represents a key
129
141
type Int32Key struct {
130
142
name string
@@ -145,11 +157,14 @@ func (k *Int32Key) Of(v int32) Tag { return Tag{Key: k, Value: v} }
145
157
// Get can be used to get a tag for the key from a TagMap.
146
158
func (k * Int32Key ) Get (tags TagMap ) int32 {
147
159
if t := tags .Find (k ); t .Valid () {
148
- return t . Value .( int32 )
160
+ return k . From ( t )
149
161
}
150
162
return 0
151
163
}
152
164
165
+ // From can be used to get a value from a Tag.
166
+ func (k * Int32Key ) From (t Tag ) int32 { return t .Value .(int32 ) }
167
+
153
168
// Int64Key represents a key
154
169
type Int64Key struct {
155
170
name string
@@ -170,11 +185,14 @@ func (k *Int64Key) Of(v int64) Tag { return Tag{Key: k, Value: v} }
170
185
// Get can be used to get a tag for the key from a TagMap.
171
186
func (k * Int64Key ) Get (tags TagMap ) int64 {
172
187
if t := tags .Find (k ); t .Valid () {
173
- return t . Value .( int64 )
188
+ return k . From ( t )
174
189
}
175
190
return 0
176
191
}
177
192
193
+ // From can be used to get a value from a Tag.
194
+ func (k * Int64Key ) From (t Tag ) int64 { return t .Value .(int64 ) }
195
+
178
196
// UIntKey represents a key
179
197
type UIntKey struct {
180
198
name string
@@ -195,11 +213,14 @@ func (k *UIntKey) Of(v uint) Tag { return Tag{Key: k, Value: v} }
195
213
// Get can be used to get a tag for the key from a TagMap.
196
214
func (k * UIntKey ) Get (tags TagMap ) uint {
197
215
if t := tags .Find (k ); t .Valid () {
198
- return t . Value .( uint )
216
+ return k . From ( t )
199
217
}
200
218
return 0
201
219
}
202
220
221
+ // From can be used to get a value from a Tag.
222
+ func (k * UIntKey ) From (t Tag ) uint { return t .Value .(uint ) }
223
+
203
224
// UInt8Key represents a key
204
225
type UInt8Key struct {
205
226
name string
@@ -220,11 +241,14 @@ func (k *UInt8Key) Of(v uint8) Tag { return Tag{Key: k, Value: v} }
220
241
// Get can be used to get a tag for the key from a TagMap.
221
242
func (k * UInt8Key ) Get (tags TagMap ) uint8 {
222
243
if t := tags .Find (k ); t .Valid () {
223
- return t . Value .( uint8 )
244
+ return k . From ( t )
224
245
}
225
246
return 0
226
247
}
227
248
249
+ // From can be used to get a value from a Tag.
250
+ func (k * UInt8Key ) From (t Tag ) uint8 { return t .Value .(uint8 ) }
251
+
228
252
// UInt16Key represents a key
229
253
type UInt16Key struct {
230
254
name string
@@ -245,11 +269,14 @@ func (k *UInt16Key) Of(v uint16) Tag { return Tag{Key: k, Value: v} }
245
269
// Get can be used to get a tag for the key from a TagMap.
246
270
func (k * UInt16Key ) Get (tags TagMap ) uint16 {
247
271
if t := tags .Find (k ); t .Valid () {
248
- return t . Value .( uint16 )
272
+ return k . From ( t )
249
273
}
250
274
return 0
251
275
}
252
276
277
+ // From can be used to get a value from a Tag.
278
+ func (k * UInt16Key ) From (t Tag ) uint16 { return t .Value .(uint16 ) }
279
+
253
280
// UInt32Key represents a key
254
281
type UInt32Key struct {
255
282
name string
@@ -270,11 +297,14 @@ func (k *UInt32Key) Of(v uint32) Tag { return Tag{Key: k, Value: v} }
270
297
// Get can be used to get a tag for the key from a TagMap.
271
298
func (k * UInt32Key ) Get (tags TagMap ) uint32 {
272
299
if t := tags .Find (k ); t .Valid () {
273
- return t . Value .( uint32 )
300
+ return k . From ( t )
274
301
}
275
302
return 0
276
303
}
277
304
305
+ // From can be used to get a value from a Tag.
306
+ func (k * UInt32Key ) From (t Tag ) uint32 { return t .Value .(uint32 ) }
307
+
278
308
// UInt64Key represents a key
279
309
type UInt64Key struct {
280
310
name string
@@ -295,11 +325,14 @@ func (k *UInt64Key) Of(v uint64) Tag { return Tag{Key: k, Value: v} }
295
325
// Get can be used to get a tag for the key from a TagMap.
296
326
func (k * UInt64Key ) Get (tags TagMap ) uint64 {
297
327
if t := tags .Find (k ); t .Valid () {
298
- return t . Value .( uint64 )
328
+ return k . From ( t )
299
329
}
300
330
return 0
301
331
}
302
332
333
+ // From can be used to get a value from a Tag.
334
+ func (k * UInt64Key ) From (t Tag ) uint64 { return t .Value .(uint64 ) }
335
+
303
336
// Float32Key represents a key
304
337
type Float32Key struct {
305
338
name string
@@ -320,11 +353,14 @@ func (k *Float32Key) Of(v float32) Tag { return Tag{Key: k, Value: v} }
320
353
// Get can be used to get a tag for the key from a TagMap.
321
354
func (k * Float32Key ) Get (tags TagMap ) float32 {
322
355
if t := tags .Find (k ); t .Valid () {
323
- return t . Value .( float32 )
356
+ return k . From ( t )
324
357
}
325
358
return 0
326
359
}
327
360
361
+ // From can be used to get a value from a Tag.
362
+ func (k * Float32Key ) From (t Tag ) float32 { return t .Value .(float32 ) }
363
+
328
364
// Float64Key represents a key
329
365
type Float64Key struct {
330
366
name string
@@ -345,11 +381,14 @@ func (k *Float64Key) Of(v float64) Tag { return Tag{Key: k, Value: v} }
345
381
// Get can be used to get a tag for the key from a TagMap.
346
382
func (k * Float64Key ) Get (tags TagMap ) float64 {
347
383
if t := tags .Find (k ); t .Valid () {
348
- return t . Value .( float64 )
384
+ return k . From ( t )
349
385
}
350
386
return 0
351
387
}
352
388
389
+ // From can be used to get a value from a Tag.
390
+ func (k * Float64Key ) From (t Tag ) float64 { return t .Value .(float64 ) }
391
+
353
392
// StringKey represents a key
354
393
type StringKey struct {
355
394
name string
@@ -370,11 +409,14 @@ func (k *StringKey) Of(v string) Tag { return Tag{Key: k, Value: v} }
370
409
// Get can be used to get a tag for the key from a TagMap.
371
410
func (k * StringKey ) Get (tags TagMap ) string {
372
411
if t := tags .Find (k ); t .Valid () {
373
- return t . Value .( string )
412
+ return k . From ( t )
374
413
}
375
414
return ""
376
415
}
377
416
417
+ // From can be used to get a value from a Tag.
418
+ func (k * StringKey ) From (t Tag ) string { return t .Value .(string ) }
419
+
378
420
// BooleanKey represents a key
379
421
type BooleanKey struct {
380
422
name string
@@ -395,11 +437,14 @@ func (k *BooleanKey) Of(v bool) Tag { return Tag{Key: k, Value: v} }
395
437
// Get can be used to get a tag for the key from a TagMap.
396
438
func (k * BooleanKey ) Get (tags TagMap ) bool {
397
439
if t := tags .Find (k ); t .Valid () {
398
- return t . Value .( bool )
440
+ return k . From ( t )
399
441
}
400
442
return false
401
443
}
402
444
445
+ // From can be used to get a value from a Tag.
446
+ func (k * BooleanKey ) From (t Tag ) bool { return t .Value .(bool ) }
447
+
403
448
// ErrorKey represents a key
404
449
type ErrorKey struct {
405
450
name string
@@ -420,7 +465,10 @@ func (k *ErrorKey) Of(v error) Tag { return Tag{Key: k, Value: v} }
420
465
// Get can be used to get a tag for the key from a TagMap.
421
466
func (k * ErrorKey ) Get (tags TagMap ) error {
422
467
if t := tags .Find (k ); t .Valid () {
423
- return t . Value .( error )
468
+ return k . From ( t )
424
469
}
425
470
return nil
426
471
}
472
+
473
+ // From can be used to get a value from a Tag.
474
+ func (k * ErrorKey ) From (t Tag ) error { return t .Value .(error ) }
0 commit comments