summaryrefslogtreecommitdiff
path: root/devdocs/go/reflect%2Findex.html
blob: fe71a6d06eed194d89f47a131dbbd6b0d911219d (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
<h1> Package reflect  </h1>     <ul id="short-nav">
<li><code>import "reflect"</code></li>
<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
<li><a href="#pkg-index" class="indexLink">Index</a></li>
<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
<li><a href="#pkg-subdirectories">Subdirectories</a></li>
</ul>     <h2 id="pkg-overview">Overview </h2> <p>Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types. The typical use is to take a value with static type interface{} and extract its dynamic type information by calling TypeOf, which returns a Type. </p>
<p>A call to ValueOf returns a Value representing the run-time data. Zero takes a Type and returns a Value representing a zero value for that type. </p>
<p>See "The Laws of Reflection" for an introduction to reflection in Go: <a href="https://golang.org/doc/articles/laws_of_reflection.html">https://golang.org/doc/articles/laws_of_reflection.html</a> </p>     <h2 id="pkg-index">Index </h2>  <ul id="manual-nav">
<li><a href="#pkg-constants">Constants</a></li>
<li><a href="#Copy">func Copy(dst, src Value) int</a></li>
<li><a href="#DeepEqual">func DeepEqual(x, y any) bool</a></li>
<li><a href="#Swapper">func Swapper(slice any) func(i, j int)</a></li>
<li><a href="#ChanDir">type ChanDir</a></li>
<li> <a href="#ChanDir.String">func (d ChanDir) String() string</a>
</li>
<li><a href="#Kind">type Kind</a></li>
<li> <a href="#Kind.String">func (k Kind) String() string</a>
</li>
<li><a href="#MapIter">type MapIter</a></li>
<li> <a href="#MapIter.Key">func (iter *MapIter) Key() Value</a>
</li>
<li> <a href="#MapIter.Next">func (iter *MapIter) Next() bool</a>
</li>
<li> <a href="#MapIter.Reset">func (iter *MapIter) Reset(v Value)</a>
</li>
<li> <a href="#MapIter.Value">func (iter *MapIter) Value() Value</a>
</li>
<li><a href="#Method">type Method</a></li>
<li> <a href="#Method.IsExported">func (m Method) IsExported() bool</a>
</li>
<li><a href="#SelectCase">type SelectCase</a></li>
<li><a href="#SelectDir">type SelectDir</a></li>
<li><a href="#SliceHeader">type SliceHeader</a></li>
<li><a href="#StringHeader">type StringHeader</a></li>
<li><a href="#StructField">type StructField</a></li>
<li> <a href="#VisibleFields">func VisibleFields(t Type) []StructField</a>
</li>
<li> <a href="#StructField.IsExported">func (f StructField) IsExported() bool</a>
</li>
<li><a href="#StructTag">type StructTag</a></li>
<li> <a href="#StructTag.Get">func (tag StructTag) Get(key string) string</a>
</li>
<li> <a href="#StructTag.Lookup">func (tag StructTag) Lookup(key string) (value string, ok bool)</a>
</li>
<li><a href="#Type">type Type</a></li>
<li> <a href="#ArrayOf">func ArrayOf(length int, elem Type) Type</a>
</li>
<li> <a href="#ChanOf">func ChanOf(dir ChanDir, t Type) Type</a>
</li>
<li> <a href="#FuncOf">func FuncOf(in, out []Type, variadic bool) Type</a>
</li>
<li> <a href="#MapOf">func MapOf(key, elem Type) Type</a>
</li>
<li> <a href="#PointerTo">func PointerTo(t Type) Type</a>
</li>
<li> <a href="#PtrTo">func PtrTo(t Type) Type</a>
</li>
<li> <a href="#SliceOf">func SliceOf(t Type) Type</a>
</li>
<li> <a href="#StructOf">func StructOf(fields []StructField) Type</a>
</li>
<li> <a href="#TypeFor">func TypeFor[T any]() Type</a>
</li>
<li> <a href="#TypeOf">func TypeOf(i any) Type</a>
</li>
<li><a href="#Value">type Value</a></li>
<li> <a href="#Append">func Append(s Value, x ...Value) Value</a>
</li>
<li> <a href="#AppendSlice">func AppendSlice(s, t Value) Value</a>
</li>
<li> <a href="#Indirect">func Indirect(v Value) Value</a>
</li>
<li> <a href="#MakeChan">func MakeChan(typ Type, buffer int) Value</a>
</li>
<li> <a href="#MakeFunc">func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value</a>
</li>
<li> <a href="#MakeMap">func MakeMap(typ Type) Value</a>
</li>
<li> <a href="#MakeMapWithSize">func MakeMapWithSize(typ Type, n int) Value</a>
</li>
<li> <a href="#MakeSlice">func MakeSlice(typ Type, len, cap int) Value</a>
</li>
<li> <a href="#New">func New(typ Type) Value</a>
</li>
<li> <a href="#NewAt">func NewAt(typ Type, p unsafe.Pointer) Value</a>
</li>
<li> <a href="#Select">func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)</a>
</li>
<li> <a href="#ValueOf">func ValueOf(i any) Value</a>
</li>
<li> <a href="#Zero">func Zero(typ Type) Value</a>
</li>
<li> <a href="#Value.Addr">func (v Value) Addr() Value</a>
</li>
<li> <a href="#Value.Bool">func (v Value) Bool() bool</a>
</li>
<li> <a href="#Value.Bytes">func (v Value) Bytes() []byte</a>
</li>
<li> <a href="#Value.Call">func (v Value) Call(in []Value) []Value</a>
</li>
<li> <a href="#Value.CallSlice">func (v Value) CallSlice(in []Value) []Value</a>
</li>
<li> <a href="#Value.CanAddr">func (v Value) CanAddr() bool</a>
</li>
<li> <a href="#Value.CanComplex">func (v Value) CanComplex() bool</a>
</li>
<li> <a href="#Value.CanConvert">func (v Value) CanConvert(t Type) bool</a>
</li>
<li> <a href="#Value.CanFloat">func (v Value) CanFloat() bool</a>
</li>
<li> <a href="#Value.CanInt">func (v Value) CanInt() bool</a>
</li>
<li> <a href="#Value.CanInterface">func (v Value) CanInterface() bool</a>
</li>
<li> <a href="#Value.CanSet">func (v Value) CanSet() bool</a>
</li>
<li> <a href="#Value.CanUint">func (v Value) CanUint() bool</a>
</li>
<li> <a href="#Value.Cap">func (v Value) Cap() int</a>
</li>
<li> <a href="#Value.Clear">func (v Value) Clear()</a>
</li>
<li> <a href="#Value.Close">func (v Value) Close()</a>
</li>
<li> <a href="#Value.Comparable">func (v Value) Comparable() bool</a>
</li>
<li> <a href="#Value.Complex">func (v Value) Complex() complex128</a>
</li>
<li> <a href="#Value.Convert">func (v Value) Convert(t Type) Value</a>
</li>
<li> <a href="#Value.Elem">func (v Value) Elem() Value</a>
</li>
<li> <a href="#Value.Equal">func (v Value) Equal(u Value) bool</a>
</li>
<li> <a href="#Value.Field">func (v Value) Field(i int) Value</a>
</li>
<li> <a href="#Value.FieldByIndex">func (v Value) FieldByIndex(index []int) Value</a>
</li>
<li> <a href="#Value.FieldByIndexErr">func (v Value) FieldByIndexErr(index []int) (Value, error)</a>
</li>
<li> <a href="#Value.FieldByName">func (v Value) FieldByName(name string) Value</a>
</li>
<li> <a href="#Value.FieldByNameFunc">func (v Value) FieldByNameFunc(match func(string) bool) Value</a>
</li>
<li> <a href="#Value.Float">func (v Value) Float() float64</a>
</li>
<li> <a href="#Value.Grow">func (v Value) Grow(n int)</a>
</li>
<li> <a href="#Value.Index">func (v Value) Index(i int) Value</a>
</li>
<li> <a href="#Value.Int">func (v Value) Int() int64</a>
</li>
<li> <a href="#Value.Interface">func (v Value) Interface() (i any)</a>
</li>
<li> <a href="#Value.InterfaceData">func (v Value) InterfaceData() [2]uintptr</a>
</li>
<li> <a href="#Value.IsNil">func (v Value) IsNil() bool</a>
</li>
<li> <a href="#Value.IsValid">func (v Value) IsValid() bool</a>
</li>
<li> <a href="#Value.IsZero">func (v Value) IsZero() bool</a>
</li>
<li> <a href="#Value.Kind">func (v Value) Kind() Kind</a>
</li>
<li> <a href="#Value.Len">func (v Value) Len() int</a>
</li>
<li> <a href="#Value.MapIndex">func (v Value) MapIndex(key Value) Value</a>
</li>
<li> <a href="#Value.MapKeys">func (v Value) MapKeys() []Value</a>
</li>
<li> <a href="#Value.MapRange">func (v Value) MapRange() *MapIter</a>
</li>
<li> <a href="#Value.Method">func (v Value) Method(i int) Value</a>
</li>
<li> <a href="#Value.MethodByName">func (v Value) MethodByName(name string) Value</a>
</li>
<li> <a href="#Value.NumField">func (v Value) NumField() int</a>
</li>
<li> <a href="#Value.NumMethod">func (v Value) NumMethod() int</a>
</li>
<li> <a href="#Value.OverflowComplex">func (v Value) OverflowComplex(x complex128) bool</a>
</li>
<li> <a href="#Value.OverflowFloat">func (v Value) OverflowFloat(x float64) bool</a>
</li>
<li> <a href="#Value.OverflowInt">func (v Value) OverflowInt(x int64) bool</a>
</li>
<li> <a href="#Value.OverflowUint">func (v Value) OverflowUint(x uint64) bool</a>
</li>
<li> <a href="#Value.Pointer">func (v Value) Pointer() uintptr</a>
</li>
<li> <a href="#Value.Recv">func (v Value) Recv() (x Value, ok bool)</a>
</li>
<li> <a href="#Value.Send">func (v Value) Send(x Value)</a>
</li>
<li> <a href="#Value.Set">func (v Value) Set(x Value)</a>
</li>
<li> <a href="#Value.SetBool">func (v Value) SetBool(x bool)</a>
</li>
<li> <a href="#Value.SetBytes">func (v Value) SetBytes(x []byte)</a>
</li>
<li> <a href="#Value.SetCap">func (v Value) SetCap(n int)</a>
</li>
<li> <a href="#Value.SetComplex">func (v Value) SetComplex(x complex128)</a>
</li>
<li> <a href="#Value.SetFloat">func (v Value) SetFloat(x float64)</a>
</li>
<li> <a href="#Value.SetInt">func (v Value) SetInt(x int64)</a>
</li>
<li> <a href="#Value.SetIterKey">func (v Value) SetIterKey(iter *MapIter)</a>
</li>
<li> <a href="#Value.SetIterValue">func (v Value) SetIterValue(iter *MapIter)</a>
</li>
<li> <a href="#Value.SetLen">func (v Value) SetLen(n int)</a>
</li>
<li> <a href="#Value.SetMapIndex">func (v Value) SetMapIndex(key, elem Value)</a>
</li>
<li> <a href="#Value.SetPointer">func (v Value) SetPointer(x unsafe.Pointer)</a>
</li>
<li> <a href="#Value.SetString">func (v Value) SetString(x string)</a>
</li>
<li> <a href="#Value.SetUint">func (v Value) SetUint(x uint64)</a>
</li>
<li> <a href="#Value.SetZero">func (v Value) SetZero()</a>
</li>
<li> <a href="#Value.Slice">func (v Value) Slice(i, j int) Value</a>
</li>
<li> <a href="#Value.Slice3">func (v Value) Slice3(i, j, k int) Value</a>
</li>
<li> <a href="#Value.String">func (v Value) String() string</a>
</li>
<li> <a href="#Value.TryRecv">func (v Value) TryRecv() (x Value, ok bool)</a>
</li>
<li> <a href="#Value.TrySend">func (v Value) TrySend(x Value) bool</a>
</li>
<li> <a href="#Value.Type">func (v Value) Type() Type</a>
</li>
<li> <a href="#Value.Uint">func (v Value) Uint() uint64</a>
</li>
<li> <a href="#Value.UnsafeAddr">func (v Value) UnsafeAddr() uintptr</a>
</li>
<li> <a href="#Value.UnsafePointer">func (v Value) UnsafePointer() unsafe.Pointer</a>
</li>
<li><a href="#ValueError">type ValueError</a></li>
<li> <a href="#ValueError.Error">func (e *ValueError) Error() string</a>
</li>
<li><a href="#pkg-note-BUG">Bugs</a></li>
</ul> <div id="pkg-examples"> <h3>Examples</h3>  <dl> <dd><a class="exampleLink" href="#example_Kind">Kind</a></dd> <dd><a class="exampleLink" href="#example_MakeFunc">MakeFunc</a></dd> <dd><a class="exampleLink" href="#example_StructOf">StructOf</a></dd> <dd><a class="exampleLink" href="#example_StructTag">StructTag</a></dd> <dd><a class="exampleLink" href="#example_StructTag_Lookup">StructTag.Lookup</a></dd> <dd><a class="exampleLink" href="#example_TypeOf">TypeOf</a></dd> <dd><a class="exampleLink" href="#example_Value_FieldByIndex">Value.FieldByIndex</a></dd> <dd><a class="exampleLink" href="#example_Value_FieldByName">Value.FieldByName</a></dd> </dl> </div> <h3>Package files</h3> <p>  <span>abi.go</span> <span>deepequal.go</span> <span>float32reg_generic.go</span> <span>makefunc.go</span> <span>swapper.go</span> <span>type.go</span> <span>value.go</span> <span>visiblefields.go</span>  </p>   <h2 id="pkg-constants">Constants</h2> <p>Ptr is the old name for the <a href="#Pointer">Pointer</a> kind. </p>
<pre data-language="go">const Ptr = Pointer</pre> <h2 id="Copy">func <span>Copy</span>  </h2> <pre data-language="go">func Copy(dst, src Value) int</pre> <p>Copy copies the contents of src into dst until either dst has been filled or src has been exhausted. It returns the number of elements copied. Dst and src each must have kind <a href="#Slice">Slice</a> or <a href="#Array">Array</a>, and dst and src must have the same element type. </p>
<p>As a special case, src can have kind <a href="#String">String</a> if the element type of dst is kind <a href="#Uint8">Uint8</a>. </p>
<h2 id="DeepEqual">func <span>DeepEqual</span>  </h2> <pre data-language="go">func DeepEqual(x, y any) bool</pre> <p>DeepEqual reports whether x and y are “deeply equal,” defined as follows. Two values of identical type are deeply equal if one of the following cases applies. Values of distinct types are never deeply equal. </p>
<p>Array values are deeply equal when their corresponding elements are deeply equal. </p>
<p>Struct values are deeply equal if their corresponding fields, both exported and unexported, are deeply equal. </p>
<p>Func values are deeply equal if both are nil; otherwise they are not deeply equal. </p>
<p>Interface values are deeply equal if they hold deeply equal concrete values. </p>
<p>Map values are deeply equal when all of the following are true: they are both nil or both non-nil, they have the same length, and either they are the same map object or their corresponding keys (matched using Go equality) map to deeply equal values. </p>
<p>Pointer values are deeply equal if they are equal using Go's == operator or if they point to deeply equal values. </p>
<p>Slice values are deeply equal when all of the following are true: they are both nil or both non-nil, they have the same length, and either they point to the same initial entry of the same underlying array (that is, &amp;x[0] == &amp;y[0]) or their corresponding elements (up to length) are deeply equal. Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil)) are not deeply equal. </p>
<p>Other values - numbers, bools, strings, and channels - are deeply equal if they are equal using Go's == operator. </p>
<p>In general DeepEqual is a recursive relaxation of Go's == operator. However, this idea is impossible to implement without some inconsistency. Specifically, it is possible for a value to be unequal to itself, either because it is of func type (uncomparable in general) or because it is a floating-point NaN value (not equal to itself in floating-point comparison), or because it is an array, struct, or interface containing such a value. On the other hand, pointer values are always equal to themselves, even if they point at or contain such problematic values, because they compare equal using Go's == operator, and that is a sufficient condition to be deeply equal, regardless of content. DeepEqual has been defined so that the same short-cut applies to slices and maps: if x and y are the same slice or the same map, they are deeply equal regardless of content. </p>
<p>As DeepEqual traverses the data values it may find a cycle. The second and subsequent times that DeepEqual compares two pointer values that have been compared before, it treats the values as equal rather than examining the values to which they point. This ensures that DeepEqual terminates. </p>
<h2 id="Swapper">func <span>Swapper</span>  <span title="Added in Go 1.8">1.8</span> </h2> <pre data-language="go">func Swapper(slice any) func(i, j int)</pre> <p>Swapper returns a function that swaps the elements in the provided slice. </p>
<p>Swapper panics if the provided interface is not a slice. </p>
<h2 id="ChanDir">type <span>ChanDir</span>  </h2> <p>ChanDir represents a channel type's direction. </p>
<pre data-language="go">type ChanDir int</pre> <pre data-language="go">const (
    RecvDir ChanDir             = 1 &lt;&lt; iota // &lt;-chan
    SendDir                                 // chan&lt;-
    BothDir = RecvDir | SendDir             // chan
)</pre> <h3 id="ChanDir.String">func (ChanDir) <span>String</span>  </h3> <pre data-language="go">func (d ChanDir) String() string</pre> <h2 id="Kind">type <span>Kind</span>  </h2> <p>A Kind represents the specific kind of type that a <a href="#Type">Type</a> represents. The zero Kind is not a valid kind. </p>
<pre data-language="go">type Kind uint</pre> <pre data-language="go">const (
    Invalid Kind = iota
    Bool
    Int
    Int8
    Int16
    Int32
    Int64
    Uint
    Uint8
    Uint16
    Uint32
    Uint64
    Uintptr
    Float32
    Float64
    Complex64
    Complex128
    Array
    Chan
    Func
    Interface
    Map
    Pointer
    Slice
    String
    Struct
    UnsafePointer
)</pre>    <h4 id="example_Kind"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">for _, v := range []any{"hi", 42, func() {}} {
    switch v := reflect.ValueOf(v); v.Kind() {
    case reflect.String:
        fmt.Println(v.String())
    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
        fmt.Println(v.Int())
    default:
        fmt.Printf("unhandled kind %s", v.Kind())
    }
}

</pre> <p>Output:</p> <pre class="output" data-language="go">hi
42
unhandled kind func
</pre>   <h3 id="Kind.String">func (Kind) <span>String</span>  </h3> <pre data-language="go">func (k Kind) String() string</pre> <p>String returns the name of k. </p>
<h2 id="MapIter">type <span>MapIter</span>  <span title="Added in Go 1.12">1.12</span> </h2> <p>A MapIter is an iterator for ranging over a map. See <a href="#Value.MapRange">Value.MapRange</a>. </p>
<pre data-language="go">type MapIter struct {
    // contains filtered or unexported fields
}
</pre> <h3 id="MapIter.Key">func (*MapIter) <span>Key</span>  <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (iter *MapIter) Key() Value</pre> <p>Key returns the key of iter's current map entry. </p>
<h3 id="MapIter.Next">func (*MapIter) <span>Next</span>  <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (iter *MapIter) Next() bool</pre> <p>Next advances the map iterator and reports whether there is another entry. It returns false when iter is exhausted; subsequent calls to <a href="#MapIter.Key">MapIter.Key</a>, <a href="#MapIter.Value">MapIter.Value</a>, or <a href="#MapIter.Next">MapIter.Next</a> will panic. </p>
<h3 id="MapIter.Reset">func (*MapIter) <span>Reset</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (iter *MapIter) Reset(v Value)</pre> <p>Reset modifies iter to iterate over v. It panics if v's Kind is not <a href="#Map">Map</a> and v is not the zero Value. Reset(Value{}) causes iter to not to refer to any map, which may allow the previously iterated-over map to be garbage collected. </p>
<h3 id="MapIter.Value">func (*MapIter) <span>Value</span>  <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (iter *MapIter) Value() Value</pre> <p>Value returns the value of iter's current map entry. </p>
<h2 id="Method">type <span>Method</span>  </h2> <p>Method represents a single method. </p>
<pre data-language="go">type Method struct {
    // Name is the method name.
    Name string

    // PkgPath is the package path that qualifies a lower case (unexported)
    // method name. It is empty for upper case (exported) method names.
    // The combination of PkgPath and Name uniquely identifies a method
    // in a method set.
    // See https://golang.org/ref/spec#Uniqueness_of_identifiers
    PkgPath string

    Type  Type  // method type
    Func  Value // func with receiver as first argument
    Index int   // index for Type.Method
}
</pre> <h3 id="Method.IsExported">func (Method) <span>IsExported</span>  <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func (m Method) IsExported() bool</pre> <p>IsExported reports whether the method is exported. </p>
<h2 id="SelectCase">type <span>SelectCase</span>  <span title="Added in Go 1.1">1.1</span> </h2> <p>A SelectCase describes a single case in a select operation. The kind of case depends on Dir, the communication direction. </p>
<p>If Dir is SelectDefault, the case represents a default case. Chan and Send must be zero Values. </p>
<p>If Dir is SelectSend, the case represents a send operation. Normally Chan's underlying value must be a channel, and Send's underlying value must be assignable to the channel's element type. As a special case, if Chan is a zero Value, then the case is ignored, and the field Send will also be ignored and may be either zero or non-zero. </p>
<p>If Dir is SelectRecv, the case represents a receive operation. Normally Chan's underlying value must be a channel and Send must be a zero Value. If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value. When a receive operation is selected, the received Value is returned by Select. </p>
<pre data-language="go">type SelectCase struct {
    Dir  SelectDir // direction of case
    Chan Value     // channel to use (for send or receive)
    Send Value     // value to send (for send)
}
</pre> <h2 id="SelectDir">type <span>SelectDir</span>  <span title="Added in Go 1.1">1.1</span> </h2> <p>A SelectDir describes the communication direction of a select case. </p>
<pre data-language="go">type SelectDir int</pre> <pre data-language="go">const (
    SelectSend    SelectDir // case Chan &lt;- Send
    SelectRecv              // case &lt;-Chan:
    SelectDefault           // default
)</pre> <h2 id="SliceHeader">type <span>SliceHeader</span>  </h2> <p>SliceHeader is the runtime representation of a slice. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data. </p>
<p>Deprecated: Use unsafe.Slice or unsafe.SliceData instead. </p>
<pre data-language="go">type SliceHeader struct {
    Data uintptr
    Len  int
    Cap  int
}
</pre> <h2 id="StringHeader">type <span>StringHeader</span>  </h2> <p>StringHeader is the runtime representation of a string. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data. </p>
<p>Deprecated: Use unsafe.String or unsafe.StringData instead. </p>
<pre data-language="go">type StringHeader struct {
    Data uintptr
    Len  int
}
</pre> <h2 id="StructField">type <span>StructField</span>  </h2> <p>A StructField describes a single field in a struct. </p>
<pre data-language="go">type StructField struct {
    // Name is the field name.
    Name string

    // PkgPath is the package path that qualifies a lower case (unexported)
    // field name. It is empty for upper case (exported) field names.
    // See https://golang.org/ref/spec#Uniqueness_of_identifiers
    PkgPath string

    Type      Type      // field type
    Tag       StructTag // field tag string
    Offset    uintptr   // offset within struct, in bytes
    Index     []int     // index sequence for Type.FieldByIndex
    Anonymous bool      // is an embedded field
}
</pre> <h3 id="VisibleFields">func <span>VisibleFields</span>  <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func VisibleFields(t Type) []StructField</pre> <p>VisibleFields returns all the visible fields in t, which must be a struct type. A field is defined as visible if it's accessible directly with a FieldByName call. The returned fields include fields inside anonymous struct members and unexported fields. They follow the same order found in the struct, with anonymous fields followed immediately by their promoted fields. </p>
<p>For each element e of the returned slice, the corresponding field can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index). </p>
<h3 id="StructField.IsExported">func (StructField) <span>IsExported</span>  <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func (f StructField) IsExported() bool</pre> <p>IsExported reports whether the field is exported. </p>
<h2 id="StructTag">type <span>StructTag</span>  </h2> <p>A StructTag is the tag string in a struct field. </p>
<p>By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax. </p>
<pre data-language="go">type StructTag string</pre>    <h4 id="example_StructTag"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">type S struct {
    F string `species:"gopher" color:"blue"`
}

s := S{}
st := reflect.TypeOf(s)
field := st.Field(0)
fmt.Println(field.Tag.Get("color"), field.Tag.Get("species"))

</pre> <p>Output:</p> <pre class="output" data-language="go">blue gopher
</pre>   <h3 id="StructTag.Get">func (StructTag) <span>Get</span>  </h3> <pre data-language="go">func (tag StructTag) Get(key string) string</pre> <p>Get returns the value associated with key in the tag string. If there is no such key in the tag, Get returns the empty string. If the tag does not have the conventional format, the value returned by Get is unspecified. To determine whether a tag is explicitly set to the empty string, use Lookup. </p>
<h3 id="StructTag.Lookup">func (StructTag) <span>Lookup</span>  <span title="Added in Go 1.7">1.7</span> </h3> <pre data-language="go">func (tag StructTag) Lookup(key string) (value string, ok bool)</pre> <p>Lookup returns the value associated with key in the tag string. If the key is present in the tag the value (which may be empty) is returned. Otherwise the returned value will be the empty string. The ok return value reports whether the value was explicitly set in the tag string. If the tag does not have the conventional format, the value returned by Lookup is unspecified. </p>   <h4 id="example_StructTag_Lookup"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">type S struct {
    F0 string `alias:"field_0"`
    F1 string `alias:""`
    F2 string
}

s := S{}
st := reflect.TypeOf(s)
for i := 0; i &lt; st.NumField(); i++ {
    field := st.Field(i)
    if alias, ok := field.Tag.Lookup("alias"); ok {
        if alias == "" {
            fmt.Println("(blank)")
        } else {
            fmt.Println(alias)
        }
    } else {
        fmt.Println("(not specified)")
    }
}

</pre> <p>Output:</p> <pre class="output" data-language="go">field_0
(blank)
(not specified)
</pre>   <h2 id="Type">type <span>Type</span>  </h2> <p>Type is the representation of a Go type. </p>
<p>Not all methods apply to all kinds of types. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of type before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run-time panic. </p>
<p>Type values are comparable, such as with the == operator, so they can be used as map keys. Two Type values are equal if they represent identical types. </p>
<pre data-language="go">type Type interface {

    // Align returns the alignment in bytes of a value of
    // this type when allocated in memory.
    Align() int

    // FieldAlign returns the alignment in bytes of a value of
    // this type when used as a field in a struct.
    FieldAlign() int

    // Method returns the i'th method in the type's method set.
    // It panics if i is not in the range [0, NumMethod()).
    //
    // For a non-interface type T or *T, the returned Method's Type and Func
    // fields describe a function whose first argument is the receiver,
    // and only exported methods are accessible.
    //
    // For an interface type, the returned Method's Type field gives the
    // method signature, without a receiver, and the Func field is nil.
    //
    // Methods are sorted in lexicographic order.
    Method(int) Method

    // MethodByName returns the method with that name in the type's
    // method set and a boolean indicating if the method was found.
    //
    // For a non-interface type T or *T, the returned Method's Type and Func
    // fields describe a function whose first argument is the receiver.
    //
    // For an interface type, the returned Method's Type field gives the
    // method signature, without a receiver, and the Func field is nil.
    MethodByName(string) (Method, bool)

    // NumMethod returns the number of methods accessible using Method.
    //
    // For a non-interface type, it returns the number of exported methods.
    //
    // For an interface type, it returns the number of exported and unexported methods.
    NumMethod() int

    // Name returns the type's name within its package for a defined type.
    // For other (non-defined) types it returns the empty string.
    Name() string

    // PkgPath returns a defined type's package path, that is, the import path
    // that uniquely identifies the package, such as "encoding/base64".
    // If the type was predeclared (string, error) or not defined (*T, struct{},
    // []int, or A where A is an alias for a non-defined type), the package path
    // will be the empty string.
    PkgPath() string

    // Size returns the number of bytes needed to store
    // a value of the given type; it is analogous to unsafe.Sizeof.
    Size() uintptr

    // String returns a string representation of the type.
    // The string representation may use shortened package names
    // (e.g., base64 instead of "encoding/base64") and is not
    // guaranteed to be unique among types. To test for type identity,
    // compare the Types directly.
    String() string

    // Kind returns the specific kind of this type.
    Kind() Kind

    // Implements reports whether the type implements the interface type u.
    Implements(u Type) bool

    // AssignableTo reports whether a value of the type is assignable to type u.
    AssignableTo(u Type) bool

    // ConvertibleTo reports whether a value of the type is convertible to type u.
    // Even if ConvertibleTo returns true, the conversion may still panic.
    // For example, a slice of type []T is convertible to *[N]T,
    // but the conversion will panic if its length is less than N.
    ConvertibleTo(u Type) bool

    // Comparable reports whether values of this type are comparable.
    // Even if Comparable returns true, the comparison may still panic.
    // For example, values of interface type are comparable,
    // but the comparison will panic if their dynamic type is not comparable.
    Comparable() bool

    // Bits returns the size of the type in bits.
    // It panics if the type's Kind is not one of the
    // sized or unsized Int, Uint, Float, or Complex kinds.
    Bits() int

    // ChanDir returns a channel type's direction.
    // It panics if the type's Kind is not Chan.
    ChanDir() ChanDir

    // IsVariadic reports whether a function type's final input parameter
    // is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's
    // implicit actual type []T.
    //
    // For concreteness, if t represents func(x int, y ... float64), then
    //
    //	t.NumIn() == 2
    //	t.In(0) is the reflect.Type for "int"
    //	t.In(1) is the reflect.Type for "[]float64"
    //	t.IsVariadic() == true
    //
    // IsVariadic panics if the type's Kind is not Func.
    IsVariadic() bool

    // Elem returns a type's element type.
    // It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice.
    Elem() Type

    // Field returns a struct type's i'th field.
    // It panics if the type's Kind is not Struct.
    // It panics if i is not in the range [0, NumField()).
    Field(i int) StructField

    // FieldByIndex returns the nested field corresponding
    // to the index sequence. It is equivalent to calling Field
    // successively for each index i.
    // It panics if the type's Kind is not Struct.
    FieldByIndex(index []int) StructField

    // FieldByName returns the struct field with the given name
    // and a boolean indicating if the field was found.
    // If the returned field is promoted from an embedded struct,
    // then Offset in the returned StructField is the offset in
    // the embedded struct.
    FieldByName(name string) (StructField, bool)

    // FieldByNameFunc returns the struct field with a name
    // that satisfies the match function and a boolean indicating if
    // the field was found.
    //
    // FieldByNameFunc considers the fields in the struct itself
    // and then the fields in any embedded structs, in breadth first order,
    // stopping at the shallowest nesting depth containing one or more
    // fields satisfying the match function. If multiple fields at that depth
    // satisfy the match function, they cancel each other
    // and FieldByNameFunc returns no match.
    // This behavior mirrors Go's handling of name lookup in
    // structs containing embedded fields.
    //
    // If the returned field is promoted from an embedded struct,
    // then Offset in the returned StructField is the offset in
    // the embedded struct.
    FieldByNameFunc(match func(string) bool) (StructField, bool)

    // In returns the type of a function type's i'th input parameter.
    // It panics if the type's Kind is not Func.
    // It panics if i is not in the range [0, NumIn()).
    In(i int) Type

    // Key returns a map type's key type.
    // It panics if the type's Kind is not Map.
    Key() Type

    // Len returns an array type's length.
    // It panics if the type's Kind is not Array.
    Len() int

    // NumField returns a struct type's field count.
    // It panics if the type's Kind is not Struct.
    NumField() int

    // NumIn returns a function type's input parameter count.
    // It panics if the type's Kind is not Func.
    NumIn() int

    // NumOut returns a function type's output parameter count.
    // It panics if the type's Kind is not Func.
    NumOut() int

    // Out returns the type of a function type's i'th output parameter.
    // It panics if the type's Kind is not Func.
    // It panics if i is not in the range [0, NumOut()).
    Out(i int) Type
    // contains filtered or unexported methods
}</pre> <h3 id="ArrayOf">func <span>ArrayOf</span>  <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func ArrayOf(length int, elem Type) Type</pre> <p>ArrayOf returns the array type with the given length and element type. For example, if t represents int, ArrayOf(5, t) represents [5]int. </p>
<p>If the resulting type would be larger than the available address space, ArrayOf panics. </p>
<h3 id="ChanOf">func <span>ChanOf</span>  <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func ChanOf(dir ChanDir, t Type) Type</pre> <p>ChanOf returns the channel type with the given direction and element type. For example, if t represents int, ChanOf(RecvDir, t) represents &lt;-chan int. </p>
<p>The gc runtime imposes a limit of 64 kB on channel element types. If t's size is equal to or exceeds this limit, ChanOf panics. </p>
<h3 id="FuncOf">func <span>FuncOf</span>  <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func FuncOf(in, out []Type, variadic bool) Type</pre> <p>FuncOf returns the function type with the given argument and result types. For example if k represents int and e represents string, FuncOf([]Type{k}, []Type{e}, false) represents func(int) string. </p>
<p>The variadic argument controls whether the function is variadic. FuncOf panics if the in[len(in)-1] does not represent a slice and variadic is true. </p>
<h3 id="MapOf">func <span>MapOf</span>  <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func MapOf(key, elem Type) Type</pre> <p>MapOf returns the map type with the given key and element types. For example, if k represents int and e represents string, MapOf(k, e) represents map[int]string. </p>
<p>If the key type is not a valid map key type (that is, if it does not implement Go's == operator), MapOf panics. </p>
<h3 id="PointerTo">func <span>PointerTo</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func PointerTo(t Type) Type</pre> <p>PointerTo returns the pointer type with element t. For example, if t represents type Foo, PointerTo(t) represents *Foo. </p>
<h3 id="PtrTo">func <span>PtrTo</span>  </h3> <pre data-language="go">func PtrTo(t Type) Type</pre> <p>PtrTo returns the pointer type with element t. For example, if t represents type Foo, PtrTo(t) represents *Foo. </p>
<p>PtrTo is the old spelling of <a href="#PointerTo">PointerTo</a>. The two functions behave identically. </p>
<p>Deprecated: Superseded by <a href="#PointerTo">PointerTo</a>. </p>
<h3 id="SliceOf">func <span>SliceOf</span>  <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func SliceOf(t Type) Type</pre> <p>SliceOf returns the slice type with element type t. For example, if t represents int, SliceOf(t) represents []int. </p>
<h3 id="StructOf">func <span>StructOf</span>  <span title="Added in Go 1.7">1.7</span> </h3> <pre data-language="go">func StructOf(fields []StructField) Type</pre> <p>StructOf returns the struct type containing fields. The Offset and Index fields are ignored and computed as they would be by the compiler. </p>
<p>StructOf currently does not support promoted methods of embedded fields and panics if passed unexported StructFields. </p>   <h4 id="example_StructOf"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">typ := reflect.StructOf([]reflect.StructField{
    {
        Name: "Height",
        Type: reflect.TypeOf(float64(0)),
        Tag:  `json:"height"`,
    },
    {
        Name: "Age",
        Type: reflect.TypeOf(int(0)),
        Tag:  `json:"age"`,
    },
})

v := reflect.New(typ).Elem()
v.Field(0).SetFloat(0.4)
v.Field(1).SetInt(2)
s := v.Addr().Interface()

w := new(bytes.Buffer)
if err := json.NewEncoder(w).Encode(s); err != nil {
    panic(err)
}

fmt.Printf("value: %+v\n", s)
fmt.Printf("json:  %s", w.Bytes())

r := bytes.NewReader([]byte(`{"height":1.5,"age":10}`))
if err := json.NewDecoder(r).Decode(s); err != nil {
    panic(err)
}
fmt.Printf("value: %+v\n", s)

</pre> <p>Output:</p> <pre class="output" data-language="go">value: &amp;{Height:0.4 Age:2}
json:  {"height":0.4,"age":2}
value: &amp;{Height:1.5 Age:10}
</pre>   <h3 id="TypeFor">func <span>TypeFor</span>  </h3> <pre data-language="go">func TypeFor[T any]() Type</pre> <p>TypeFor returns the <a href="#Type">Type</a> that represents the type argument T. </p>
<h3 id="TypeOf">func <span>TypeOf</span>  </h3> <pre data-language="go">func TypeOf(i any) Type</pre> <p>TypeOf returns the reflection <a href="#Type">Type</a> that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil. </p>   <h4 id="example_TypeOf"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">// As interface types are only used for static typing, a
// common idiom to find the reflection Type for an interface
// type Foo is to use a *Foo value.
writerType := reflect.TypeOf((*io.Writer)(nil)).Elem()

fileType := reflect.TypeOf((*os.File)(nil))
fmt.Println(fileType.Implements(writerType))

</pre> <p>Output:</p> <pre class="output" data-language="go">true
</pre>   <h2 id="Value">type <span>Value</span>  </h2> <p>Value is the reflection interface to a Go value. </p>
<p>Not all methods apply to all kinds of values. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of value before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run time panic. </p>
<p>The zero Value represents no value. Its IsValid method returns false, its Kind method returns Invalid, its String method returns "&lt;invalid Value&gt;", and all other methods panic. Most functions and methods never return an invalid value. If one does, its documentation states the conditions explicitly. </p>
<p>A Value can be used concurrently by multiple goroutines provided that the underlying Go value can be used concurrently for the equivalent direct operations. </p>
<p>To compare two Values, compare the results of the Interface method. Using == on two Values does not compare the underlying values they represent. </p>
<pre data-language="go">type Value struct {
    // contains filtered or unexported fields
}
</pre> <h3 id="Append">func <span>Append</span>  </h3> <pre data-language="go">func Append(s Value, x ...Value) Value</pre> <p>Append appends the values x to a slice s and returns the resulting slice. As in Go, each x's value must be assignable to the slice's element type. </p>
<h3 id="AppendSlice">func <span>AppendSlice</span>  </h3> <pre data-language="go">func AppendSlice(s, t Value) Value</pre> <p>AppendSlice appends a slice t to a slice s and returns the resulting slice. The slices s and t must have the same element type. </p>
<h3 id="Indirect">func <span>Indirect</span>  </h3> <pre data-language="go">func Indirect(v Value) Value</pre> <p>Indirect returns the value that v points to. If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v. </p>
<h3 id="MakeChan">func <span>MakeChan</span>  </h3> <pre data-language="go">func MakeChan(typ Type, buffer int) Value</pre> <p>MakeChan creates a new channel with the specified type and buffer size. </p>
<h3 id="MakeFunc">func <span>MakeFunc</span>  <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value</pre> <p>MakeFunc returns a new function of the given Type that wraps the function fn. When called, that new function does the following: </p>
<ul> <li>converts its arguments to a slice of Values. </li>
<li>runs results := fn(args). </li>
<li>returns the results as a slice of Values, one per formal result. </li>
</ul> <p>The implementation fn can assume that the argument Value slice has the number and type of arguments given by typ. If typ describes a variadic function, the final Value is itself a slice representing the variadic arguments, as in the body of a variadic function. The result Value slice returned by fn must have the number and type of results given by typ. </p>
<p>The Value.Call method allows the caller to invoke a typed function in terms of Values; in contrast, MakeFunc allows the caller to implement a typed function in terms of Values. </p>
<p>The Examples section of the documentation includes an illustration of how to use MakeFunc to build a swap function for different types. </p>   <h4 id="example_MakeFunc"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">// swap is the implementation passed to MakeFunc.
// It must work in terms of reflect.Values so that it is possible
// to write code without knowing beforehand what the types
// will be.
swap := func(in []reflect.Value) []reflect.Value {
    return []reflect.Value{in[1], in[0]}
}

// makeSwap expects fptr to be a pointer to a nil function.
// It sets that pointer to a new function created with MakeFunc.
// When the function is invoked, reflect turns the arguments
// into Values, calls swap, and then turns swap's result slice
// into the values returned by the new function.
makeSwap := func(fptr any) {
    // fptr is a pointer to a function.
    // Obtain the function value itself (likely nil) as a reflect.Value
    // so that we can query its type and then set the value.
    fn := reflect.ValueOf(fptr).Elem()

    // Make a function of the right type.
    v := reflect.MakeFunc(fn.Type(), swap)

    // Assign it to the value fn represents.
    fn.Set(v)
}

// Make and call a swap function for ints.
var intSwap func(int, int) (int, int)
makeSwap(&amp;intSwap)
fmt.Println(intSwap(0, 1))

// Make and call a swap function for float64s.
var floatSwap func(float64, float64) (float64, float64)
makeSwap(&amp;floatSwap)
fmt.Println(floatSwap(2.72, 3.14))

</pre> <p>Output:</p> <pre class="output" data-language="go">1 0
3.14 2.72
</pre>   <h3 id="MakeMap">func <span>MakeMap</span>  </h3> <pre data-language="go">func MakeMap(typ Type) Value</pre> <p>MakeMap creates a new map with the specified type. </p>
<h3 id="MakeMapWithSize">func <span>MakeMapWithSize</span>  <span title="Added in Go 1.9">1.9</span> </h3> <pre data-language="go">func MakeMapWithSize(typ Type, n int) Value</pre> <p>MakeMapWithSize creates a new map with the specified type and initial space for approximately n elements. </p>
<h3 id="MakeSlice">func <span>MakeSlice</span>  </h3> <pre data-language="go">func MakeSlice(typ Type, len, cap int) Value</pre> <p>MakeSlice creates a new zero-initialized slice value for the specified slice type, length, and capacity. </p>
<h3 id="New">func <span>New</span>  </h3> <pre data-language="go">func New(typ Type) Value</pre> <p>New returns a Value representing a pointer to a new zero value for the specified type. That is, the returned Value's Type is PointerTo(typ). </p>
<h3 id="NewAt">func <span>NewAt</span>  </h3> <pre data-language="go">func NewAt(typ Type, p unsafe.Pointer) Value</pre> <p>NewAt returns a Value representing a pointer to a value of the specified type, using p as that pointer. </p>
<h3 id="Select">func <span>Select</span>  <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)</pre> <p>Select executes a select operation described by the list of cases. Like the Go select statement, it blocks until at least one of the cases can proceed, makes a uniform pseudo-random choice, and then executes that case. It returns the index of the chosen case and, if that case was a receive operation, the value received and a boolean indicating whether the value corresponds to a send on the channel (as opposed to a zero value received because the channel is closed). Select supports a maximum of 65536 cases. </p>
<h3 id="ValueOf">func <span>ValueOf</span>  </h3> <pre data-language="go">func ValueOf(i any) Value</pre> <p>ValueOf returns a new Value initialized to the concrete value stored in the interface i. ValueOf(nil) returns the zero Value. </p>
<h3 id="Zero">func <span>Zero</span>  </h3> <pre data-language="go">func Zero(typ Type) Value</pre> <p>Zero returns a Value representing the zero value for the specified type. The result is different from the zero value of the Value struct, which represents no value at all. For example, Zero(TypeOf(42)) returns a Value with Kind <a href="#Int">Int</a> and value 0. The returned value is neither addressable nor settable. </p>
<h3 id="Value.Addr">func (Value) <span>Addr</span>  </h3> <pre data-language="go">func (v Value) Addr() Value</pre> <p>Addr returns a pointer value representing the address of v. It panics if <a href="#Value.CanAddr">Value.CanAddr</a> returns false. Addr is typically used to obtain a pointer to a struct field or slice element in order to call a method that requires a pointer receiver. </p>
<h3 id="Value.Bool">func (Value) <span>Bool</span>  </h3> <pre data-language="go">func (v Value) Bool() bool</pre> <p>Bool returns v's underlying value. It panics if v's kind is not <a href="#Bool">Bool</a>. </p>
<h3 id="Value.Bytes">func (Value) <span>Bytes</span>  </h3> <pre data-language="go">func (v Value) Bytes() []byte</pre> <p>Bytes returns v's underlying value. It panics if v's underlying value is not a slice of bytes or an addressable array of bytes. </p>
<h3 id="Value.Call">func (Value) <span>Call</span>  </h3> <pre data-language="go">func (v Value) Call(in []Value) []Value</pre> <p>Call calls the function v with the input arguments in. For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]). Call panics if v's Kind is not <a href="#Func">Func</a>. It returns the output results as Values. As in Go, each input argument must be assignable to the type of the function's corresponding input parameter. If v is a variadic function, Call creates the variadic slice parameter itself, copying in the corresponding values. </p>
<h3 id="Value.CallSlice">func (Value) <span>CallSlice</span>  </h3> <pre data-language="go">func (v Value) CallSlice(in []Value) []Value</pre> <p>CallSlice calls the variadic function v with the input arguments in, assigning the slice in[len(in)-1] to v's final variadic argument. For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...). CallSlice panics if v's Kind is not <a href="#Func">Func</a> or if v is not variadic. It returns the output results as Values. As in Go, each input argument must be assignable to the type of the function's corresponding input parameter. </p>
<h3 id="Value.CanAddr">func (Value) <span>CanAddr</span>  </h3> <pre data-language="go">func (v Value) CanAddr() bool</pre> <p>CanAddr reports whether the value's address can be obtained with <a href="#Value.Addr">Value.Addr</a>. Such values are called addressable. A value is addressable if it is an element of a slice, an element of an addressable array, a field of an addressable struct, or the result of dereferencing a pointer. If CanAddr returns false, calling <a href="#Value.Addr">Value.Addr</a> will panic. </p>
<h3 id="Value.CanComplex">func (Value) <span>CanComplex</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) CanComplex() bool</pre> <p>CanComplex reports whether <a href="#Value.Complex">Value.Complex</a> can be used without panicking. </p>
<h3 id="Value.CanConvert">func (Value) <span>CanConvert</span>  <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func (v Value) CanConvert(t Type) bool</pre> <p>CanConvert reports whether the value v can be converted to type t. If v.CanConvert(t) returns true then v.Convert(t) will not panic. </p>
<h3 id="Value.CanFloat">func (Value) <span>CanFloat</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) CanFloat() bool</pre> <p>CanFloat reports whether <a href="#Value.Float">Value.Float</a> can be used without panicking. </p>
<h3 id="Value.CanInt">func (Value) <span>CanInt</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) CanInt() bool</pre> <p>CanInt reports whether Int can be used without panicking. </p>
<h3 id="Value.CanInterface">func (Value) <span>CanInterface</span>  </h3> <pre data-language="go">func (v Value) CanInterface() bool</pre> <p>CanInterface reports whether <a href="#Value.Interface">Value.Interface</a> can be used without panicking. </p>
<h3 id="Value.CanSet">func (Value) <span>CanSet</span>  </h3> <pre data-language="go">func (v Value) CanSet() bool</pre> <p>CanSet reports whether the value of v can be changed. A <a href="#Value">Value</a> can be changed only if it is addressable and was not obtained by the use of unexported struct fields. If CanSet returns false, calling <a href="#Value.Set">Value.Set</a> or any type-specific setter (e.g., <a href="#Value.SetBool">Value.SetBool</a>, <a href="#Value.SetInt">Value.SetInt</a>) will panic. </p>
<h3 id="Value.CanUint">func (Value) <span>CanUint</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) CanUint() bool</pre> <p>CanUint reports whether <a href="#Value.Uint">Value.Uint</a> can be used without panicking. </p>
<h3 id="Value.Cap">func (Value) <span>Cap</span>  </h3> <pre data-language="go">func (v Value) Cap() int</pre> <p>Cap returns v's capacity. It panics if v's Kind is not <a href="#Array">Array</a>, <a href="#Chan">Chan</a>, <a href="#Slice">Slice</a> or pointer to <a href="#Array">Array</a>. </p>
<h3 id="Value.Clear">func (Value) <span>Clear</span>  <span title="Added in Go 1.21">1.21</span> </h3> <pre data-language="go">func (v Value) Clear()</pre> <p>Clear clears the contents of a map or zeros the contents of a slice. </p>
<p>It panics if v's Kind is not <a href="#Map">Map</a> or <a href="#Slice">Slice</a>. </p>
<h3 id="Value.Close">func (Value) <span>Close</span>  </h3> <pre data-language="go">func (v Value) Close()</pre> <p>Close closes the channel v. It panics if v's Kind is not <a href="#Chan">Chan</a> or v is a receive-only channel. </p>
<h3 id="Value.Comparable">func (Value) <span>Comparable</span>  <span title="Added in Go 1.20">1.20</span> </h3> <pre data-language="go">func (v Value) Comparable() bool</pre> <p>Comparable reports whether the value v is comparable. If the type of v is an interface, this checks the dynamic type. If this reports true then v.Interface() == x will not panic for any x, nor will v.Equal(u) for any Value u. </p>
<h3 id="Value.Complex">func (Value) <span>Complex</span>  </h3> <pre data-language="go">func (v Value) Complex() complex128</pre> <p>Complex returns v's underlying value, as a complex128. It panics if v's Kind is not <a href="#Complex64">Complex64</a> or <a href="#Complex128">Complex128</a> </p>
<h3 id="Value.Convert">func (Value) <span>Convert</span>  <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func (v Value) Convert(t Type) Value</pre> <p>Convert returns the value v converted to type t. If the usual Go conversion rules do not allow conversion of the value v to type t, or if converting v to type t panics, Convert panics. </p>
<h3 id="Value.Elem">func (Value) <span>Elem</span>  </h3> <pre data-language="go">func (v Value) Elem() Value</pre> <p>Elem returns the value that the interface v contains or that the pointer v points to. It panics if v's Kind is not <a href="#Interface">Interface</a> or <a href="#Pointer">Pointer</a>. It returns the zero Value if v is nil. </p>
<h3 id="Value.Equal">func (Value) <span>Equal</span>  <span title="Added in Go 1.20">1.20</span> </h3> <pre data-language="go">func (v Value) Equal(u Value) bool</pre> <p>Equal reports true if v is equal to u. For two invalid values, Equal will report true. For an interface value, Equal will compare the value within the interface. Otherwise, If the values have different types, Equal will report false. Otherwise, for arrays and structs Equal will compare each element in order, and report false if it finds non-equal elements. During all comparisons, if values of the same type are compared, and the type is not comparable, Equal will panic. </p>
<h3 id="Value.Field">func (Value) <span>Field</span>  </h3> <pre data-language="go">func (v Value) Field(i int) Value</pre> <p>Field returns the i'th field of the struct v. It panics if v's Kind is not <a href="#Struct">Struct</a> or i is out of range. </p>
<h3 id="Value.FieldByIndex">func (Value) <span>FieldByIndex</span>  </h3> <pre data-language="go">func (v Value) FieldByIndex(index []int) Value</pre> <p>FieldByIndex returns the nested field corresponding to index. It panics if evaluation requires stepping through a nil pointer or a field that is not a struct. </p>   <h4 id="example_Value_FieldByIndex"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">// This example shows a case in which the name of a promoted field
// is hidden by another field: FieldByName will not work, so
// FieldByIndex must be used instead.
type user struct {
    firstName string
    lastName  string
}

type data struct {
    user
    firstName string
    lastName  string
}

u := data{
    user:      user{"Embedded John", "Embedded Doe"},
    firstName: "John",
    lastName:  "Doe",
}

s := reflect.ValueOf(u).FieldByIndex([]int{0, 1})
fmt.Println("embedded last name:", s)

</pre> <p>Output:</p> <pre class="output" data-language="go">embedded last name: Embedded Doe
</pre>   <h3 id="Value.FieldByIndexErr">func (Value) <span>FieldByIndexErr</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) FieldByIndexErr(index []int) (Value, error)</pre> <p>FieldByIndexErr returns the nested field corresponding to index. It returns an error if evaluation requires stepping through a nil pointer, but panics if it must step through a field that is not a struct. </p>
<h3 id="Value.FieldByName">func (Value) <span>FieldByName</span>  </h3> <pre data-language="go">func (v Value) FieldByName(name string) Value</pre> <p>FieldByName returns the struct field with the given name. It returns the zero Value if no field was found. It panics if v's Kind is not <a href="#Struct">Struct</a>. </p>   <h4 id="example_Value_FieldByName"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">type user struct {
    firstName string
    lastName  string
}
u := user{firstName: "John", lastName: "Doe"}
s := reflect.ValueOf(u)

fmt.Println("Name:", s.FieldByName("firstName"))
</pre> <p>Output:</p> <pre class="output" data-language="go">Name: John
</pre>   <h3 id="Value.FieldByNameFunc">func (Value) <span>FieldByNameFunc</span>  </h3> <pre data-language="go">func (v Value) FieldByNameFunc(match func(string) bool) Value</pre> <p>FieldByNameFunc returns the struct field with a name that satisfies the match function. It panics if v's Kind is not <a href="#Struct">Struct</a>. It returns the zero Value if no field was found. </p>
<h3 id="Value.Float">func (Value) <span>Float</span>  </h3> <pre data-language="go">func (v Value) Float() float64</pre> <p>Float returns v's underlying value, as a float64. It panics if v's Kind is not <a href="#Float32">Float32</a> or <a href="#Float64">Float64</a> </p>
<h3 id="Value.Grow">func (Value) <span>Grow</span>  <span title="Added in Go 1.20">1.20</span> </h3> <pre data-language="go">func (v Value) Grow(n int)</pre> <p>Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. </p>
<p>It panics if v's Kind is not a <a href="#Slice">Slice</a> or if n is negative or too large to allocate the memory. </p>
<h3 id="Value.Index">func (Value) <span>Index</span>  </h3> <pre data-language="go">func (v Value) Index(i int) Value</pre> <p>Index returns v's i'th element. It panics if v's Kind is not <a href="#Array">Array</a>, <a href="#Slice">Slice</a>, or <a href="#String">String</a> or i is out of range. </p>
<h3 id="Value.Int">func (Value) <span>Int</span>  </h3> <pre data-language="go">func (v Value) Int() int64</pre> <p>Int returns v's underlying value, as an int64. It panics if v's Kind is not <a href="#Int">Int</a>, <a href="#Int8">Int8</a>, <a href="#Int16">Int16</a>, <a href="#Int32">Int32</a>, or <a href="#Int64">Int64</a>. </p>
<h3 id="Value.Interface">func (Value) <span>Interface</span>  </h3> <pre data-language="go">func (v Value) Interface() (i any)</pre> <p>Interface returns v's current value as an interface{}. It is equivalent to: </p>
<pre data-language="go">var i interface{} = (v's underlying value)
</pre> <p>It panics if the Value was obtained by accessing unexported struct fields. </p>
<h3 id="Value.InterfaceData">func (Value) <span>InterfaceData</span>  </h3> <pre data-language="go">func (v Value) InterfaceData() [2]uintptr</pre> <p>InterfaceData returns a pair of unspecified uintptr values. It panics if v's Kind is not Interface. </p>
<p>In earlier versions of Go, this function returned the interface's value as a uintptr pair. As of Go 1.4, the implementation of interface values precludes any defined use of InterfaceData. </p>
<p>Deprecated: The memory representation of interface values is not compatible with InterfaceData. </p>
<h3 id="Value.IsNil">func (Value) <span>IsNil</span>  </h3> <pre data-language="go">func (v Value) IsNil() bool</pre> <p>IsNil reports whether its argument v is nil. The argument must be a chan, func, interface, map, pointer, or slice value; if it is not, IsNil panics. Note that IsNil is not always equivalent to a regular comparison with nil in Go. For example, if v was created by calling ValueOf with an uninitialized interface variable i, i==nil will be true but v.IsNil will panic as v will be the zero Value. </p>
<h3 id="Value.IsValid">func (Value) <span>IsValid</span>  </h3> <pre data-language="go">func (v Value) IsValid() bool</pre> <p>IsValid reports whether v represents a value. It returns false if v is the zero Value. If IsValid returns false, all other methods except String panic. Most functions and methods never return an invalid Value. If one does, its documentation states the conditions explicitly. </p>
<h3 id="Value.IsZero">func (Value) <span>IsZero</span>  <span title="Added in Go 1.13">1.13</span> </h3> <pre data-language="go">func (v Value) IsZero() bool</pre> <p>IsZero reports whether v is the zero value for its type. It panics if the argument is invalid. </p>
<h3 id="Value.Kind">func (Value) <span>Kind</span>  </h3> <pre data-language="go">func (v Value) Kind() Kind</pre> <p>Kind returns v's Kind. If v is the zero Value (<a href="#Value.IsValid">Value.IsValid</a> returns false), Kind returns Invalid. </p>
<h3 id="Value.Len">func (Value) <span>Len</span>  </h3> <pre data-language="go">func (v Value) Len() int</pre> <p>Len returns v's length. It panics if v's Kind is not <a href="#Array">Array</a>, <a href="#Chan">Chan</a>, <a href="#Map">Map</a>, <a href="#Slice">Slice</a>, <a href="#String">String</a>, or pointer to <a href="#Array">Array</a>. </p>
<h3 id="Value.MapIndex">func (Value) <span>MapIndex</span>  </h3> <pre data-language="go">func (v Value) MapIndex(key Value) Value</pre> <p>MapIndex returns the value associated with key in the map v. It panics if v's Kind is not <a href="#Map">Map</a>. It returns the zero Value if key is not found in the map or if v represents a nil map. As in Go, the key's value must be assignable to the map's key type. </p>
<h3 id="Value.MapKeys">func (Value) <span>MapKeys</span>  </h3> <pre data-language="go">func (v Value) MapKeys() []Value</pre> <p>MapKeys returns a slice containing all the keys present in the map, in unspecified order. It panics if v's Kind is not <a href="#Map">Map</a>. It returns an empty slice if v represents a nil map. </p>
<h3 id="Value.MapRange">func (Value) <span>MapRange</span>  <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (v Value) MapRange() *MapIter</pre> <p>MapRange returns a range iterator for a map. It panics if v's Kind is not <a href="#Map">Map</a>. </p>
<p>Call <a href="#MapIter.Next">MapIter.Next</a> to advance the iterator, and <a href="#MapIter.Key">MapIter.Key</a>/<a href="#MapIter.Value">MapIter.Value</a> to access each entry. <a href="#MapIter.Next">MapIter.Next</a> returns false when the iterator is exhausted. MapRange follows the same iteration semantics as a range statement. </p>
<p>Example: </p>
<pre data-language="go">iter := reflect.ValueOf(m).MapRange()
for iter.Next() {
	k := iter.Key()
	v := iter.Value()
	...
}
</pre> <h3 id="Value.Method">func (Value) <span>Method</span>  </h3> <pre data-language="go">func (v Value) Method(i int) Value</pre> <p>Method returns a function value corresponding to v's i'th method. The arguments to a Call on the returned function should not include a receiver; the returned function will always use v as the receiver. Method panics if i is out of range or if v is a nil interface value. </p>
<h3 id="Value.MethodByName">func (Value) <span>MethodByName</span>  </h3> <pre data-language="go">func (v Value) MethodByName(name string) Value</pre> <p>MethodByName returns a function value corresponding to the method of v with the given name. The arguments to a Call on the returned function should not include a receiver; the returned function will always use v as the receiver. It returns the zero Value if no method was found. </p>
<h3 id="Value.NumField">func (Value) <span>NumField</span>  </h3> <pre data-language="go">func (v Value) NumField() int</pre> <p>NumField returns the number of fields in the struct v. It panics if v's Kind is not <a href="#Struct">Struct</a>. </p>
<h3 id="Value.NumMethod">func (Value) <span>NumMethod</span>  </h3> <pre data-language="go">func (v Value) NumMethod() int</pre> <p>NumMethod returns the number of methods in the value's method set. </p>
<p>For a non-interface type, it returns the number of exported methods. </p>
<p>For an interface type, it returns the number of exported and unexported methods. </p>
<h3 id="Value.OverflowComplex">func (Value) <span>OverflowComplex</span>  </h3> <pre data-language="go">func (v Value) OverflowComplex(x complex128) bool</pre> <p>OverflowComplex reports whether the complex128 x cannot be represented by v's type. It panics if v's Kind is not <a href="#Complex64">Complex64</a> or <a href="#Complex128">Complex128</a>. </p>
<h3 id="Value.OverflowFloat">func (Value) <span>OverflowFloat</span>  </h3> <pre data-language="go">func (v Value) OverflowFloat(x float64) bool</pre> <p>OverflowFloat reports whether the float64 x cannot be represented by v's type. It panics if v's Kind is not <a href="#Float32">Float32</a> or <a href="#Float64">Float64</a>. </p>
<h3 id="Value.OverflowInt">func (Value) <span>OverflowInt</span>  </h3> <pre data-language="go">func (v Value) OverflowInt(x int64) bool</pre> <p>OverflowInt reports whether the int64 x cannot be represented by v's type. It panics if v's Kind is not <a href="#Int">Int</a>, <a href="#Int8">Int8</a>, <a href="#Int16">Int16</a>, <a href="#Int32">Int32</a>, or <a href="#Int64">Int64</a>. </p>
<h3 id="Value.OverflowUint">func (Value) <span>OverflowUint</span>  </h3> <pre data-language="go">func (v Value) OverflowUint(x uint64) bool</pre> <p>OverflowUint reports whether the uint64 x cannot be represented by v's type. It panics if v's Kind is not <a href="#Uint">Uint</a>, <a href="#Uintptr">Uintptr</a>, <a href="#Uint8">Uint8</a>, <a href="#Uint16">Uint16</a>, <a href="#Uint32">Uint32</a>, or <a href="#Uint64">Uint64</a>. </p>
<h3 id="Value.Pointer">func (Value) <span>Pointer</span>  </h3> <pre data-language="go">func (v Value) Pointer() uintptr</pre> <p>Pointer returns v's value as a uintptr. It panics if v's Kind is not <a href="#Chan">Chan</a>, <a href="#Func">Func</a>, <a href="#Map">Map</a>, <a href="#Pointer">Pointer</a>, <a href="#Slice">Slice</a>, or <a href="#UnsafePointer">UnsafePointer</a>. </p>
<p>If v's Kind is <a href="#Func">Func</a>, the returned pointer is an underlying code pointer, but not necessarily enough to identify a single function uniquely. The only guarantee is that the result is zero if and only if v is a nil func Value. </p>
<p>If v's Kind is <a href="#Slice">Slice</a>, the returned pointer is to the first element of the slice. If the slice is nil the returned value is 0. If the slice is empty but non-nil the return value is non-zero. </p>
<p>It's preferred to use uintptr(Value.UnsafePointer()) to get the equivalent result. </p>
<h3 id="Value.Recv">func (Value) <span>Recv</span>  </h3> <pre data-language="go">func (v Value) Recv() (x Value, ok bool)</pre> <p>Recv receives and returns a value from the channel v. It panics if v's Kind is not <a href="#Chan">Chan</a>. The receive blocks until a value is ready. The boolean value ok is true if the value x corresponds to a send on the channel, false if it is a zero value received because the channel is closed. </p>
<h3 id="Value.Send">func (Value) <span>Send</span>  </h3> <pre data-language="go">func (v Value) Send(x Value)</pre> <p>Send sends x on the channel v. It panics if v's kind is not <a href="#Chan">Chan</a> or if x's type is not the same type as v's element type. As in Go, x's value must be assignable to the channel's element type. </p>
<h3 id="Value.Set">func (Value) <span>Set</span>  </h3> <pre data-language="go">func (v Value) Set(x Value)</pre> <p>Set assigns x to the value v. It panics if <a href="#Value.CanSet">Value.CanSet</a> returns false. As in Go, x's value must be assignable to v's type and must not be derived from an unexported field. </p>
<h3 id="Value.SetBool">func (Value) <span>SetBool</span>  </h3> <pre data-language="go">func (v Value) SetBool(x bool)</pre> <p>SetBool sets v's underlying value. It panics if v's Kind is not <a href="#Bool">Bool</a> or if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.SetBytes">func (Value) <span>SetBytes</span>  </h3> <pre data-language="go">func (v Value) SetBytes(x []byte)</pre> <p>SetBytes sets v's underlying value. It panics if v's underlying value is not a slice of bytes. </p>
<h3 id="Value.SetCap">func (Value) <span>SetCap</span>  <span title="Added in Go 1.2">1.2</span> </h3> <pre data-language="go">func (v Value) SetCap(n int)</pre> <p>SetCap sets v's capacity to n. It panics if v's Kind is not <a href="#Slice">Slice</a> or if n is smaller than the length or greater than the capacity of the slice. </p>
<h3 id="Value.SetComplex">func (Value) <span>SetComplex</span>  </h3> <pre data-language="go">func (v Value) SetComplex(x complex128)</pre> <p>SetComplex sets v's underlying value to x. It panics if v's Kind is not <a href="#Complex64">Complex64</a> or <a href="#Complex128">Complex128</a>, or if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.SetFloat">func (Value) <span>SetFloat</span>  </h3> <pre data-language="go">func (v Value) SetFloat(x float64)</pre> <p>SetFloat sets v's underlying value to x. It panics if v's Kind is not <a href="#Float32">Float32</a> or <a href="#Float64">Float64</a>, or if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.SetInt">func (Value) <span>SetInt</span>  </h3> <pre data-language="go">func (v Value) SetInt(x int64)</pre> <p>SetInt sets v's underlying value to x. It panics if v's Kind is not <a href="#Int">Int</a>, <a href="#Int8">Int8</a>, <a href="#Int16">Int16</a>, <a href="#Int32">Int32</a>, or <a href="#Int64">Int64</a>, or if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.SetIterKey">func (Value) <span>SetIterKey</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) SetIterKey(iter *MapIter)</pre> <p>SetIterKey assigns to v the key of iter's current map entry. It is equivalent to v.Set(iter.Key()), but it avoids allocating a new Value. As in Go, the key must be assignable to v's type and must not be derived from an unexported field. </p>
<h3 id="Value.SetIterValue">func (Value) <span>SetIterValue</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) SetIterValue(iter *MapIter)</pre> <p>SetIterValue assigns to v the value of iter's current map entry. It is equivalent to v.Set(iter.Value()), but it avoids allocating a new Value. As in Go, the value must be assignable to v's type and must not be derived from an unexported field. </p>
<h3 id="Value.SetLen">func (Value) <span>SetLen</span>  </h3> <pre data-language="go">func (v Value) SetLen(n int)</pre> <p>SetLen sets v's length to n. It panics if v's Kind is not <a href="#Slice">Slice</a> or if n is negative or greater than the capacity of the slice. </p>
<h3 id="Value.SetMapIndex">func (Value) <span>SetMapIndex</span>  </h3> <pre data-language="go">func (v Value) SetMapIndex(key, elem Value)</pre> <p>SetMapIndex sets the element associated with key in the map v to elem. It panics if v's Kind is not <a href="#Map">Map</a>. If elem is the zero Value, SetMapIndex deletes the key from the map. Otherwise if v holds a nil map, SetMapIndex will panic. As in Go, key's elem must be assignable to the map's key type, and elem's value must be assignable to the map's elem type. </p>
<h3 id="Value.SetPointer">func (Value) <span>SetPointer</span>  </h3> <pre data-language="go">func (v Value) SetPointer(x unsafe.Pointer)</pre> <p>SetPointer sets the <span>unsafe.Pointer</span> value v to x. It panics if v's Kind is not UnsafePointer. </p>
<h3 id="Value.SetString">func (Value) <span>SetString</span>  </h3> <pre data-language="go">func (v Value) SetString(x string)</pre> <p>SetString sets v's underlying value to x. It panics if v's Kind is not <a href="#String">String</a> or if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.SetUint">func (Value) <span>SetUint</span>  </h3> <pre data-language="go">func (v Value) SetUint(x uint64)</pre> <p>SetUint sets v's underlying value to x. It panics if v's Kind is not <a href="#Uint">Uint</a>, <a href="#Uintptr">Uintptr</a>, <a href="#Uint8">Uint8</a>, <a href="#Uint16">Uint16</a>, <a href="#Uint32">Uint32</a>, or <a href="#Uint64">Uint64</a>, or if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.SetZero">func (Value) <span>SetZero</span>  <span title="Added in Go 1.20">1.20</span> </h3> <pre data-language="go">func (v Value) SetZero()</pre> <p>SetZero sets v to be the zero value of v's type. It panics if <a href="#Value.CanSet">Value.CanSet</a> returns false. </p>
<h3 id="Value.Slice">func (Value) <span>Slice</span>  </h3> <pre data-language="go">func (v Value) Slice(i, j int) Value</pre> <p>Slice returns v[i:j]. It panics if v's Kind is not <a href="#Array">Array</a>, <a href="#Slice">Slice</a> or <a href="#String">String</a>, or if v is an unaddressable array, or if the indexes are out of bounds. </p>
<h3 id="Value.Slice3">func (Value) <span>Slice3</span>  <span title="Added in Go 1.2">1.2</span> </h3> <pre data-language="go">func (v Value) Slice3(i, j, k int) Value</pre> <p>Slice3 is the 3-index form of the slice operation: it returns v[i:j:k]. It panics if v's Kind is not <a href="#Array">Array</a> or <a href="#Slice">Slice</a>, or if v is an unaddressable array, or if the indexes are out of bounds. </p>
<h3 id="Value.String">func (Value) <span>String</span>  </h3> <pre data-language="go">func (v Value) String() string</pre> <p>String returns the string v's underlying value, as a string. String is a special case because of Go's String method convention. Unlike the other getters, it does not panic if v's Kind is not <a href="#String">String</a>. Instead, it returns a string of the form "&lt;T value&gt;" where T is v's type. The fmt package treats Values specially. It does not call their String method implicitly but instead prints the concrete values they hold. </p>
<h3 id="Value.TryRecv">func (Value) <span>TryRecv</span>  </h3> <pre data-language="go">func (v Value) TryRecv() (x Value, ok bool)</pre> <p>TryRecv attempts to receive a value from the channel v but will not block. It panics if v's Kind is not <a href="#Chan">Chan</a>. If the receive delivers a value, x is the transferred value and ok is true. If the receive cannot finish without blocking, x is the zero Value and ok is false. If the channel is closed, x is the zero value for the channel's element type and ok is false. </p>
<h3 id="Value.TrySend">func (Value) <span>TrySend</span>  </h3> <pre data-language="go">func (v Value) TrySend(x Value) bool</pre> <p>TrySend attempts to send x on the channel v but will not block. It panics if v's Kind is not <a href="#Chan">Chan</a>. It reports whether the value was sent. As in Go, x's value must be assignable to the channel's element type. </p>
<h3 id="Value.Type">func (Value) <span>Type</span>  </h3> <pre data-language="go">func (v Value) Type() Type</pre> <p>Type returns v's type. </p>
<h3 id="Value.Uint">func (Value) <span>Uint</span>  </h3> <pre data-language="go">func (v Value) Uint() uint64</pre> <p>Uint returns v's underlying value, as a uint64. It panics if v's Kind is not <a href="#Uint">Uint</a>, <a href="#Uintptr">Uintptr</a>, <a href="#Uint8">Uint8</a>, <a href="#Uint16">Uint16</a>, <a href="#Uint32">Uint32</a>, or <a href="#Uint64">Uint64</a>. </p>
<h3 id="Value.UnsafeAddr">func (Value) <span>UnsafeAddr</span>  </h3> <pre data-language="go">func (v Value) UnsafeAddr() uintptr</pre> <p>UnsafeAddr returns a pointer to v's data, as a uintptr. It panics if v is not addressable. </p>
<p>It's preferred to use uintptr(Value.Addr().UnsafePointer()) to get the equivalent result. </p>
<h3 id="Value.UnsafePointer">func (Value) <span>UnsafePointer</span>  <span title="Added in Go 1.18">1.18</span> </h3> <pre data-language="go">func (v Value) UnsafePointer() unsafe.Pointer</pre> <p>UnsafePointer returns v's value as a <span>unsafe.Pointer</span>. It panics if v's Kind is not <a href="#Chan">Chan</a>, <a href="#Func">Func</a>, <a href="#Map">Map</a>, <a href="#Pointer">Pointer</a>, <a href="#Slice">Slice</a>, or <a href="#UnsafePointer">UnsafePointer</a>. </p>
<p>If v's Kind is <a href="#Func">Func</a>, the returned pointer is an underlying code pointer, but not necessarily enough to identify a single function uniquely. The only guarantee is that the result is zero if and only if v is a nil func Value. </p>
<p>If v's Kind is <a href="#Slice">Slice</a>, the returned pointer is to the first element of the slice. If the slice is nil the returned value is nil. If the slice is empty but non-nil the return value is non-nil. </p>
<h2 id="ValueError">type <span>ValueError</span>  </h2> <p>A ValueError occurs when a Value method is invoked on a <a href="#Value">Value</a> that does not support it. Such cases are documented in the description of each method. </p>
<pre data-language="go">type ValueError struct {
    Method string
    Kind   Kind
}
</pre> <h3 id="ValueError.Error">func (*ValueError) <span>Error</span>  </h3> <pre data-language="go">func (e *ValueError) Error() string</pre> <h2 id="pkg-note-BUG">Bugs</h2> <ul> <li>☞ <p>FieldByName and related functions consider struct field names to be equal if the names are equal, even if they are unexported names originating in different packages. The practical effect of this is that the result of t.FieldByName("x") is not well defined if the struct type t contains multiple fields named x (embedded from different packages). FieldByName may return one of the fields named x or may report that there are none. See <a href="https://golang.org/issue/4876">https://golang.org/issue/4876</a> for more details. </p>
</li> </ul> <h2 id="pkg-subdirectories">Subdirectories</h2> <div class="pkg-dir"> <table> <tr> <th class="pkg-name">Name</th> <th class="pkg-synopsis">Synopsis</th> </tr> <tr> <td colspan="2"><a href="../index">..</a></td> </tr> </table> </div><div class="_attribution">
  <p class="_attribution-p">
    &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
    <a href="http://golang.org/pkg/reflect/" class="_attribution-link">http://golang.org/pkg/reflect/</a>
  </p>
</div>