reflect.TypeOf() returns reflect.Type and reflect.ValueOf() returns reflect.Value . A reflect.Type allows reflect.Type to request information that is bound to all variables of the same type, while reflect.Value allows reflect.Value to request information and pre-processing data of an arbitrary type.
In the above example, you use reflect.Type to get the "tag" of the first field in the Person structure. You start with a type for *Person . To get information about the type of Person , you used t.Elem() . Then you pulled the tag information about the first field using .Field(0).Tag . The actual value you passed, i , does not matter, since the tag of the first field is part of the type.
You used reflect.Value to get a string representation of the first field of the i value. First you used v.Elem() to get the value for the structure pointed to by i , then .Field(0) first data of the field ( .Field(0) ) and finally turned that data into a string ( .String() ).
source share