Reflection
Reflection is an advanced Go feature that allows you to dynamically learn the type of an arbitrary object, as well as information about its structure. Go offers the reflect package for working with reflection. What you should remember is that you will most likely not need to use reflection in every Go program. So, the first two questions are: why is reflection necessary and when should you use it?
Reflection is necessary for the implementation of packages such as fmt, text/template, and html/template. In the fmt package, reflection saves you from having to explicitly deal with every data type that exists. However, even if you had the patience to write code to work with every data type that you know of, you would still not be able ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access