Reflection in Go

reflect.TypeOf()

  • object with various methods that return info about the type of the var

varType.Name()

  • not all vars have name (type), for example slices and pointers don’t but a user defined struct like Foo has a name of Foo

varType.Kind()

  • a Foo struct would have a type of Foo and a kind of struct; the kind is what the type is made of: struct, pointer, slice etc

varType.Elem()

  • the contained type in the case of slices and arrays, maps, channels and pointers