-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
You might be wondering how you can find out the names of the fields of a structure at execution time. In such cases, you need to use reflection. Reflection provides a powerful, albeit low-level, mechanism to inspect and manipulate program values at runtime. While systems programming often favors performance, determinism, and type safety, there are cases where runtime flexibility is not just useful but necessary – such as when building debuggers, serializers, or generic utilities. The Go reflect package offers access to the internal types of a program's metadata and value representations, enabling developers to write code that can adapt to types it has never seen before. Apart from enabling you to print the fields and the values of a structure, reflection allows you to explore and manipulate unknown structures, such as the ones created from decoding JSON data.
The most useful parts of the reflect package are two data types named reflect.Value and reflect.Type. reflect...