blob: 6743930b82363976aae28639741e5189504249c1 [file] [log] [blame]
khenaidooac637102019-01-14 15:44:34 -05001// Copyright (c) 2016 Uber Technologies, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21package zap
22
23import (
24 "fmt"
25 "math"
26 "time"
27
Abhay Kumara2ae5992025-11-10 14:02:24 +000028 "go.uber.org/zap/internal/stacktrace"
khenaidooac637102019-01-14 15:44:34 -050029 "go.uber.org/zap/zapcore"
30)
31
32// Field is an alias for Field. Aliasing this type dramatically
33// improves the navigability of this package's API documentation.
34type Field = zapcore.Field
35
khenaidood948f772021-08-11 17:49:24 -040036var (
37 _minTimeInt64 = time.Unix(0, math.MinInt64)
38 _maxTimeInt64 = time.Unix(0, math.MaxInt64)
39)
40
khenaidooac637102019-01-14 15:44:34 -050041// Skip constructs a no-op field, which is often useful when handling invalid
42// inputs in other Field constructors.
43func Skip() Field {
44 return Field{Type: zapcore.SkipType}
45}
46
khenaidood948f772021-08-11 17:49:24 -040047// nilField returns a field which will marshal explicitly as nil. See motivation
48// in https://github.com/uber-go/zap/issues/753 . If we ever make breaking
49// changes and add zapcore.NilType and zapcore.ObjectEncoder.AddNil, the
50// implementation here should be changed to reflect that.
51func nilField(key string) Field { return Reflect(key, nil) }
52
khenaidooac637102019-01-14 15:44:34 -050053// Binary constructs a field that carries an opaque binary blob.
54//
55// Binary data is serialized in an encoding-appropriate format. For example,
56// zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text,
57// use ByteString.
58func Binary(key string, val []byte) Field {
59 return Field{Key: key, Type: zapcore.BinaryType, Interface: val}
60}
61
62// Bool constructs a field that carries a bool.
63func Bool(key string, val bool) Field {
64 var ival int64
65 if val {
66 ival = 1
67 }
68 return Field{Key: key, Type: zapcore.BoolType, Integer: ival}
69}
70
khenaidood948f772021-08-11 17:49:24 -040071// Boolp constructs a field that carries a *bool. The returned Field will safely
72// and explicitly represent `nil` when appropriate.
73func Boolp(key string, val *bool) Field {
74 if val == nil {
75 return nilField(key)
76 }
77 return Bool(key, *val)
78}
79
khenaidooac637102019-01-14 15:44:34 -050080// ByteString constructs a field that carries UTF-8 encoded text as a []byte.
81// To log opaque binary blobs (which aren't necessarily valid UTF-8), use
82// Binary.
83func ByteString(key string, val []byte) Field {
84 return Field{Key: key, Type: zapcore.ByteStringType, Interface: val}
85}
86
87// Complex128 constructs a field that carries a complex number. Unlike most
88// numeric fields, this costs an allocation (to convert the complex128 to
89// interface{}).
90func Complex128(key string, val complex128) Field {
91 return Field{Key: key, Type: zapcore.Complex128Type, Interface: val}
92}
93
khenaidood948f772021-08-11 17:49:24 -040094// Complex128p constructs a field that carries a *complex128. The returned Field will safely
95// and explicitly represent `nil` when appropriate.
96func Complex128p(key string, val *complex128) Field {
97 if val == nil {
98 return nilField(key)
99 }
100 return Complex128(key, *val)
101}
102
khenaidooac637102019-01-14 15:44:34 -0500103// Complex64 constructs a field that carries a complex number. Unlike most
104// numeric fields, this costs an allocation (to convert the complex64 to
105// interface{}).
106func Complex64(key string, val complex64) Field {
107 return Field{Key: key, Type: zapcore.Complex64Type, Interface: val}
108}
109
khenaidood948f772021-08-11 17:49:24 -0400110// Complex64p constructs a field that carries a *complex64. The returned Field will safely
111// and explicitly represent `nil` when appropriate.
112func Complex64p(key string, val *complex64) Field {
113 if val == nil {
114 return nilField(key)
115 }
116 return Complex64(key, *val)
117}
118
khenaidooac637102019-01-14 15:44:34 -0500119// Float64 constructs a field that carries a float64. The way the
120// floating-point value is represented is encoder-dependent, so marshaling is
121// necessarily lazy.
122func Float64(key string, val float64) Field {
123 return Field{Key: key, Type: zapcore.Float64Type, Integer: int64(math.Float64bits(val))}
124}
125
khenaidood948f772021-08-11 17:49:24 -0400126// Float64p constructs a field that carries a *float64. The returned Field will safely
127// and explicitly represent `nil` when appropriate.
128func Float64p(key string, val *float64) Field {
129 if val == nil {
130 return nilField(key)
131 }
132 return Float64(key, *val)
133}
134
khenaidooac637102019-01-14 15:44:34 -0500135// Float32 constructs a field that carries a float32. The way the
136// floating-point value is represented is encoder-dependent, so marshaling is
137// necessarily lazy.
138func Float32(key string, val float32) Field {
139 return Field{Key: key, Type: zapcore.Float32Type, Integer: int64(math.Float32bits(val))}
140}
141
khenaidood948f772021-08-11 17:49:24 -0400142// Float32p constructs a field that carries a *float32. The returned Field will safely
143// and explicitly represent `nil` when appropriate.
144func Float32p(key string, val *float32) Field {
145 if val == nil {
146 return nilField(key)
147 }
148 return Float32(key, *val)
149}
150
khenaidooac637102019-01-14 15:44:34 -0500151// Int constructs a field with the given key and value.
152func Int(key string, val int) Field {
153 return Int64(key, int64(val))
154}
155
khenaidood948f772021-08-11 17:49:24 -0400156// Intp constructs a field that carries a *int. The returned Field will safely
157// and explicitly represent `nil` when appropriate.
158func Intp(key string, val *int) Field {
159 if val == nil {
160 return nilField(key)
161 }
162 return Int(key, *val)
163}
164
khenaidooac637102019-01-14 15:44:34 -0500165// Int64 constructs a field with the given key and value.
166func Int64(key string, val int64) Field {
167 return Field{Key: key, Type: zapcore.Int64Type, Integer: val}
168}
169
khenaidood948f772021-08-11 17:49:24 -0400170// Int64p constructs a field that carries a *int64. The returned Field will safely
171// and explicitly represent `nil` when appropriate.
172func Int64p(key string, val *int64) Field {
173 if val == nil {
174 return nilField(key)
175 }
176 return Int64(key, *val)
177}
178
khenaidooac637102019-01-14 15:44:34 -0500179// Int32 constructs a field with the given key and value.
180func Int32(key string, val int32) Field {
181 return Field{Key: key, Type: zapcore.Int32Type, Integer: int64(val)}
182}
183
khenaidood948f772021-08-11 17:49:24 -0400184// Int32p constructs a field that carries a *int32. The returned Field will safely
185// and explicitly represent `nil` when appropriate.
186func Int32p(key string, val *int32) Field {
187 if val == nil {
188 return nilField(key)
189 }
190 return Int32(key, *val)
191}
192
khenaidooac637102019-01-14 15:44:34 -0500193// Int16 constructs a field with the given key and value.
194func Int16(key string, val int16) Field {
195 return Field{Key: key, Type: zapcore.Int16Type, Integer: int64(val)}
196}
197
khenaidood948f772021-08-11 17:49:24 -0400198// Int16p constructs a field that carries a *int16. The returned Field will safely
199// and explicitly represent `nil` when appropriate.
200func Int16p(key string, val *int16) Field {
201 if val == nil {
202 return nilField(key)
203 }
204 return Int16(key, *val)
205}
206
khenaidooac637102019-01-14 15:44:34 -0500207// Int8 constructs a field with the given key and value.
208func Int8(key string, val int8) Field {
209 return Field{Key: key, Type: zapcore.Int8Type, Integer: int64(val)}
210}
211
khenaidood948f772021-08-11 17:49:24 -0400212// Int8p constructs a field that carries a *int8. The returned Field will safely
213// and explicitly represent `nil` when appropriate.
214func Int8p(key string, val *int8) Field {
215 if val == nil {
216 return nilField(key)
217 }
218 return Int8(key, *val)
219}
220
khenaidooac637102019-01-14 15:44:34 -0500221// String constructs a field with the given key and value.
222func String(key string, val string) Field {
223 return Field{Key: key, Type: zapcore.StringType, String: val}
224}
225
khenaidood948f772021-08-11 17:49:24 -0400226// Stringp constructs a field that carries a *string. The returned Field will safely
227// and explicitly represent `nil` when appropriate.
228func Stringp(key string, val *string) Field {
229 if val == nil {
230 return nilField(key)
231 }
232 return String(key, *val)
233}
234
khenaidooac637102019-01-14 15:44:34 -0500235// Uint constructs a field with the given key and value.
236func Uint(key string, val uint) Field {
237 return Uint64(key, uint64(val))
238}
239
khenaidood948f772021-08-11 17:49:24 -0400240// Uintp constructs a field that carries a *uint. The returned Field will safely
241// and explicitly represent `nil` when appropriate.
242func Uintp(key string, val *uint) Field {
243 if val == nil {
244 return nilField(key)
245 }
246 return Uint(key, *val)
247}
248
khenaidooac637102019-01-14 15:44:34 -0500249// Uint64 constructs a field with the given key and value.
250func Uint64(key string, val uint64) Field {
251 return Field{Key: key, Type: zapcore.Uint64Type, Integer: int64(val)}
252}
253
khenaidood948f772021-08-11 17:49:24 -0400254// Uint64p constructs a field that carries a *uint64. The returned Field will safely
255// and explicitly represent `nil` when appropriate.
256func Uint64p(key string, val *uint64) Field {
257 if val == nil {
258 return nilField(key)
259 }
260 return Uint64(key, *val)
261}
262
khenaidooac637102019-01-14 15:44:34 -0500263// Uint32 constructs a field with the given key and value.
264func Uint32(key string, val uint32) Field {
265 return Field{Key: key, Type: zapcore.Uint32Type, Integer: int64(val)}
266}
267
khenaidood948f772021-08-11 17:49:24 -0400268// Uint32p constructs a field that carries a *uint32. The returned Field will safely
269// and explicitly represent `nil` when appropriate.
270func Uint32p(key string, val *uint32) Field {
271 if val == nil {
272 return nilField(key)
273 }
274 return Uint32(key, *val)
275}
276
khenaidooac637102019-01-14 15:44:34 -0500277// Uint16 constructs a field with the given key and value.
278func Uint16(key string, val uint16) Field {
279 return Field{Key: key, Type: zapcore.Uint16Type, Integer: int64(val)}
280}
281
khenaidood948f772021-08-11 17:49:24 -0400282// Uint16p constructs a field that carries a *uint16. The returned Field will safely
283// and explicitly represent `nil` when appropriate.
284func Uint16p(key string, val *uint16) Field {
285 if val == nil {
286 return nilField(key)
287 }
288 return Uint16(key, *val)
289}
290
khenaidooac637102019-01-14 15:44:34 -0500291// Uint8 constructs a field with the given key and value.
292func Uint8(key string, val uint8) Field {
293 return Field{Key: key, Type: zapcore.Uint8Type, Integer: int64(val)}
294}
295
khenaidood948f772021-08-11 17:49:24 -0400296// Uint8p constructs a field that carries a *uint8. The returned Field will safely
297// and explicitly represent `nil` when appropriate.
298func Uint8p(key string, val *uint8) Field {
299 if val == nil {
300 return nilField(key)
301 }
302 return Uint8(key, *val)
303}
304
khenaidooac637102019-01-14 15:44:34 -0500305// Uintptr constructs a field with the given key and value.
306func Uintptr(key string, val uintptr) Field {
307 return Field{Key: key, Type: zapcore.UintptrType, Integer: int64(val)}
308}
309
khenaidood948f772021-08-11 17:49:24 -0400310// Uintptrp constructs a field that carries a *uintptr. The returned Field will safely
311// and explicitly represent `nil` when appropriate.
312func Uintptrp(key string, val *uintptr) Field {
313 if val == nil {
314 return nilField(key)
315 }
316 return Uintptr(key, *val)
317}
318
khenaidooac637102019-01-14 15:44:34 -0500319// Reflect constructs a field with the given key and an arbitrary object. It uses
320// an encoding-appropriate, reflection-based function to lazily serialize nearly
321// any object into the logging context, but it's relatively slow and
322// allocation-heavy. Outside tests, Any is always a better choice.
323//
324// If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect
325// includes the error message in the final log output.
326func Reflect(key string, val interface{}) Field {
327 return Field{Key: key, Type: zapcore.ReflectType, Interface: val}
328}
329
330// Namespace creates a named, isolated scope within the logger's context. All
331// subsequent fields will be added to the new namespace.
332//
333// This helps prevent key collisions when injecting loggers into sub-components
334// or third-party libraries.
335func Namespace(key string) Field {
336 return Field{Key: key, Type: zapcore.NamespaceType}
337}
338
339// Stringer constructs a field with the given key and the output of the value's
340// String method. The Stringer's String method is called lazily.
341func Stringer(key string, val fmt.Stringer) Field {
342 return Field{Key: key, Type: zapcore.StringerType, Interface: val}
343}
344
345// Time constructs a Field with the given key and value. The encoder
346// controls how the time is serialized.
347func Time(key string, val time.Time) Field {
khenaidood948f772021-08-11 17:49:24 -0400348 if val.Before(_minTimeInt64) || val.After(_maxTimeInt64) {
349 return Field{Key: key, Type: zapcore.TimeFullType, Interface: val}
350 }
khenaidooac637102019-01-14 15:44:34 -0500351 return Field{Key: key, Type: zapcore.TimeType, Integer: val.UnixNano(), Interface: val.Location()}
352}
353
khenaidood948f772021-08-11 17:49:24 -0400354// Timep constructs a field that carries a *time.Time. The returned Field will safely
355// and explicitly represent `nil` when appropriate.
356func Timep(key string, val *time.Time) Field {
357 if val == nil {
358 return nilField(key)
359 }
360 return Time(key, *val)
361}
362
khenaidooac637102019-01-14 15:44:34 -0500363// Stack constructs a field that stores a stacktrace of the current goroutine
364// under provided key. Keep in mind that taking a stacktrace is eager and
365// expensive (relatively speaking); this function both makes an allocation and
366// takes about two microseconds.
367func Stack(key string) Field {
khenaidood948f772021-08-11 17:49:24 -0400368 return StackSkip(key, 1) // skip Stack
369}
370
371// StackSkip constructs a field similarly to Stack, but also skips the given
372// number of frames from the top of the stacktrace.
373func StackSkip(key string, skip int) Field {
khenaidooac637102019-01-14 15:44:34 -0500374 // Returning the stacktrace as a string costs an allocation, but saves us
375 // from expanding the zapcore.Field union struct to include a byte slice. Since
376 // taking a stacktrace is already so expensive (~10us), the extra allocation
377 // is okay.
Abhay Kumara2ae5992025-11-10 14:02:24 +0000378 return String(key, stacktrace.Take(skip+1)) // skip StackSkip
khenaidooac637102019-01-14 15:44:34 -0500379}
380
381// Duration constructs a field with the given key and value. The encoder
382// controls how the duration is serialized.
383func Duration(key string, val time.Duration) Field {
384 return Field{Key: key, Type: zapcore.DurationType, Integer: int64(val)}
385}
386
khenaidood948f772021-08-11 17:49:24 -0400387// Durationp constructs a field that carries a *time.Duration. The returned Field will safely
388// and explicitly represent `nil` when appropriate.
389func Durationp(key string, val *time.Duration) Field {
390 if val == nil {
391 return nilField(key)
392 }
393 return Duration(key, *val)
394}
395
khenaidooac637102019-01-14 15:44:34 -0500396// Object constructs a field with the given key and ObjectMarshaler. It
397// provides a flexible, but still type-safe and efficient, way to add map- or
398// struct-like user-defined types to the logging context. The struct's
399// MarshalLogObject method is called lazily.
400func Object(key string, val zapcore.ObjectMarshaler) Field {
401 return Field{Key: key, Type: zapcore.ObjectMarshalerType, Interface: val}
402}
403
khenaidood948f772021-08-11 17:49:24 -0400404// Inline constructs a Field that is similar to Object, but it
405// will add the elements of the provided ObjectMarshaler to the
406// current namespace.
407func Inline(val zapcore.ObjectMarshaler) Field {
408 return zapcore.Field{
409 Type: zapcore.InlineMarshalerType,
410 Interface: val,
411 }
412}
413
Abhay Kumara2ae5992025-11-10 14:02:24 +0000414// Dict constructs a field containing the provided key-value pairs.
415// It acts similar to [Object], but with the fields specified as arguments.
416func Dict(key string, val ...Field) Field {
417 return dictField(key, val)
418}
419
420// We need a function with the signature (string, T) for zap.Any.
421func dictField(key string, val []Field) Field {
422 return Object(key, dictObject(val))
423}
424
425type dictObject []Field
426
427func (d dictObject) MarshalLogObject(enc zapcore.ObjectEncoder) error {
428 for _, f := range d {
429 f.AddTo(enc)
430 }
431 return nil
432}
433
434// We discovered an issue where zap.Any can cause a performance degradation
435// when used in new goroutines.
436//
437// This happens because the compiler assigns 4.8kb (one zap.Field per arm of
438// switch statement) of stack space for zap.Any when it takes the form:
439//
440// switch v := v.(type) {
441// case string:
442// return String(key, v)
443// case int:
444// return Int(key, v)
445// // ...
446// default:
447// return Reflect(key, v)
448// }
449//
450// To avoid this, we use the type switch to assign a value to a single local variable
451// and then call a function on it.
452// The local variable is just a function reference so it doesn't allocate
453// when converted to an interface{}.
454//
455// A fair bit of experimentation went into this.
456// See also:
457//
458// - https://github.com/uber-go/zap/pull/1301
459// - https://github.com/uber-go/zap/pull/1303
460// - https://github.com/uber-go/zap/pull/1304
461// - https://github.com/uber-go/zap/pull/1305
462// - https://github.com/uber-go/zap/pull/1308
463//
464// See https://github.com/golang/go/issues/62077 for upstream issue.
465type anyFieldC[T any] func(string, T) Field
466
467func (f anyFieldC[T]) Any(key string, val any) Field {
468 v, _ := val.(T)
469 // val is guaranteed to be a T, except when it's nil.
470 return f(key, v)
471}
472
khenaidooac637102019-01-14 15:44:34 -0500473// Any takes a key and an arbitrary value and chooses the best way to represent
474// them as a field, falling back to a reflection-based approach only if
475// necessary.
476//
477// Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between
478// them. To minimize surprises, []byte values are treated as binary blobs, byte
479// values are treated as uint8, and runes are always treated as integers.
480func Any(key string, value interface{}) Field {
Abhay Kumara2ae5992025-11-10 14:02:24 +0000481 var c interface{ Any(string, any) Field }
482
483 switch value.(type) {
khenaidooac637102019-01-14 15:44:34 -0500484 case zapcore.ObjectMarshaler:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000485 c = anyFieldC[zapcore.ObjectMarshaler](Object)
khenaidooac637102019-01-14 15:44:34 -0500486 case zapcore.ArrayMarshaler:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000487 c = anyFieldC[zapcore.ArrayMarshaler](Array)
488 case []Field:
489 c = anyFieldC[[]Field](dictField)
khenaidooac637102019-01-14 15:44:34 -0500490 case bool:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000491 c = anyFieldC[bool](Bool)
khenaidood948f772021-08-11 17:49:24 -0400492 case *bool:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000493 c = anyFieldC[*bool](Boolp)
khenaidooac637102019-01-14 15:44:34 -0500494 case []bool:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000495 c = anyFieldC[[]bool](Bools)
khenaidooac637102019-01-14 15:44:34 -0500496 case complex128:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000497 c = anyFieldC[complex128](Complex128)
khenaidood948f772021-08-11 17:49:24 -0400498 case *complex128:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000499 c = anyFieldC[*complex128](Complex128p)
khenaidooac637102019-01-14 15:44:34 -0500500 case []complex128:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000501 c = anyFieldC[[]complex128](Complex128s)
khenaidooac637102019-01-14 15:44:34 -0500502 case complex64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000503 c = anyFieldC[complex64](Complex64)
khenaidood948f772021-08-11 17:49:24 -0400504 case *complex64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000505 c = anyFieldC[*complex64](Complex64p)
khenaidooac637102019-01-14 15:44:34 -0500506 case []complex64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000507 c = anyFieldC[[]complex64](Complex64s)
khenaidooac637102019-01-14 15:44:34 -0500508 case float64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000509 c = anyFieldC[float64](Float64)
khenaidood948f772021-08-11 17:49:24 -0400510 case *float64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000511 c = anyFieldC[*float64](Float64p)
khenaidooac637102019-01-14 15:44:34 -0500512 case []float64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000513 c = anyFieldC[[]float64](Float64s)
khenaidooac637102019-01-14 15:44:34 -0500514 case float32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000515 c = anyFieldC[float32](Float32)
khenaidood948f772021-08-11 17:49:24 -0400516 case *float32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000517 c = anyFieldC[*float32](Float32p)
khenaidooac637102019-01-14 15:44:34 -0500518 case []float32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000519 c = anyFieldC[[]float32](Float32s)
khenaidooac637102019-01-14 15:44:34 -0500520 case int:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000521 c = anyFieldC[int](Int)
khenaidood948f772021-08-11 17:49:24 -0400522 case *int:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000523 c = anyFieldC[*int](Intp)
khenaidooac637102019-01-14 15:44:34 -0500524 case []int:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000525 c = anyFieldC[[]int](Ints)
khenaidooac637102019-01-14 15:44:34 -0500526 case int64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000527 c = anyFieldC[int64](Int64)
khenaidood948f772021-08-11 17:49:24 -0400528 case *int64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000529 c = anyFieldC[*int64](Int64p)
khenaidooac637102019-01-14 15:44:34 -0500530 case []int64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000531 c = anyFieldC[[]int64](Int64s)
khenaidooac637102019-01-14 15:44:34 -0500532 case int32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000533 c = anyFieldC[int32](Int32)
khenaidood948f772021-08-11 17:49:24 -0400534 case *int32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000535 c = anyFieldC[*int32](Int32p)
khenaidooac637102019-01-14 15:44:34 -0500536 case []int32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000537 c = anyFieldC[[]int32](Int32s)
khenaidooac637102019-01-14 15:44:34 -0500538 case int16:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000539 c = anyFieldC[int16](Int16)
khenaidood948f772021-08-11 17:49:24 -0400540 case *int16:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000541 c = anyFieldC[*int16](Int16p)
khenaidooac637102019-01-14 15:44:34 -0500542 case []int16:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000543 c = anyFieldC[[]int16](Int16s)
khenaidooac637102019-01-14 15:44:34 -0500544 case int8:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000545 c = anyFieldC[int8](Int8)
khenaidood948f772021-08-11 17:49:24 -0400546 case *int8:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000547 c = anyFieldC[*int8](Int8p)
khenaidooac637102019-01-14 15:44:34 -0500548 case []int8:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000549 c = anyFieldC[[]int8](Int8s)
khenaidooac637102019-01-14 15:44:34 -0500550 case string:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000551 c = anyFieldC[string](String)
khenaidood948f772021-08-11 17:49:24 -0400552 case *string:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000553 c = anyFieldC[*string](Stringp)
khenaidooac637102019-01-14 15:44:34 -0500554 case []string:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000555 c = anyFieldC[[]string](Strings)
khenaidooac637102019-01-14 15:44:34 -0500556 case uint:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000557 c = anyFieldC[uint](Uint)
khenaidood948f772021-08-11 17:49:24 -0400558 case *uint:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000559 c = anyFieldC[*uint](Uintp)
khenaidooac637102019-01-14 15:44:34 -0500560 case []uint:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000561 c = anyFieldC[[]uint](Uints)
khenaidooac637102019-01-14 15:44:34 -0500562 case uint64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000563 c = anyFieldC[uint64](Uint64)
khenaidood948f772021-08-11 17:49:24 -0400564 case *uint64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000565 c = anyFieldC[*uint64](Uint64p)
khenaidooac637102019-01-14 15:44:34 -0500566 case []uint64:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000567 c = anyFieldC[[]uint64](Uint64s)
khenaidooac637102019-01-14 15:44:34 -0500568 case uint32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000569 c = anyFieldC[uint32](Uint32)
khenaidood948f772021-08-11 17:49:24 -0400570 case *uint32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000571 c = anyFieldC[*uint32](Uint32p)
khenaidooac637102019-01-14 15:44:34 -0500572 case []uint32:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000573 c = anyFieldC[[]uint32](Uint32s)
khenaidooac637102019-01-14 15:44:34 -0500574 case uint16:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000575 c = anyFieldC[uint16](Uint16)
khenaidood948f772021-08-11 17:49:24 -0400576 case *uint16:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000577 c = anyFieldC[*uint16](Uint16p)
khenaidooac637102019-01-14 15:44:34 -0500578 case []uint16:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000579 c = anyFieldC[[]uint16](Uint16s)
khenaidooac637102019-01-14 15:44:34 -0500580 case uint8:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000581 c = anyFieldC[uint8](Uint8)
khenaidood948f772021-08-11 17:49:24 -0400582 case *uint8:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000583 c = anyFieldC[*uint8](Uint8p)
khenaidooac637102019-01-14 15:44:34 -0500584 case []byte:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000585 c = anyFieldC[[]byte](Binary)
khenaidooac637102019-01-14 15:44:34 -0500586 case uintptr:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000587 c = anyFieldC[uintptr](Uintptr)
khenaidood948f772021-08-11 17:49:24 -0400588 case *uintptr:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000589 c = anyFieldC[*uintptr](Uintptrp)
khenaidooac637102019-01-14 15:44:34 -0500590 case []uintptr:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000591 c = anyFieldC[[]uintptr](Uintptrs)
khenaidooac637102019-01-14 15:44:34 -0500592 case time.Time:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000593 c = anyFieldC[time.Time](Time)
khenaidood948f772021-08-11 17:49:24 -0400594 case *time.Time:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000595 c = anyFieldC[*time.Time](Timep)
khenaidooac637102019-01-14 15:44:34 -0500596 case []time.Time:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000597 c = anyFieldC[[]time.Time](Times)
khenaidooac637102019-01-14 15:44:34 -0500598 case time.Duration:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000599 c = anyFieldC[time.Duration](Duration)
khenaidood948f772021-08-11 17:49:24 -0400600 case *time.Duration:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000601 c = anyFieldC[*time.Duration](Durationp)
khenaidooac637102019-01-14 15:44:34 -0500602 case []time.Duration:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000603 c = anyFieldC[[]time.Duration](Durations)
khenaidooac637102019-01-14 15:44:34 -0500604 case error:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000605 c = anyFieldC[error](NamedError)
khenaidooac637102019-01-14 15:44:34 -0500606 case []error:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000607 c = anyFieldC[[]error](Errors)
khenaidooac637102019-01-14 15:44:34 -0500608 case fmt.Stringer:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000609 c = anyFieldC[fmt.Stringer](Stringer)
khenaidooac637102019-01-14 15:44:34 -0500610 default:
Abhay Kumara2ae5992025-11-10 14:02:24 +0000611 c = anyFieldC[any](Reflect)
khenaidooac637102019-01-14 15:44:34 -0500612 }
Abhay Kumara2ae5992025-11-10 14:02:24 +0000613
614 return c.Any(key, value)
khenaidooac637102019-01-14 15:44:34 -0500615}