Developers are often told reflection is bad and should be avoided. However, when reflection can help reduce the amount of code needed to solve a problem, it should be considered. Reducing complexity while preserving maintainability must always be a priority. Reflection can be a tool that helps makes this possible. In this talk I am going to show you the power and elegance of the reflection package.
https://candysmurf.github.io/GoReflectionTalk
http://blog.golang.org/laws-of-reflection
Example shows how to reflect over a struct type value.
Struct Types (Go Playground)
Example shows how to reflect over a slice of struct type values.
Slices (Go Playground)
Example shows how to reflect over a map of struct type values.
Maps (Go Playground)
Example shows how to reflect over a struct type pointer.
Pointers (Go Playground)
Example shows how to reflect over a struct type value that is stored inside an interface value.
Struct Types (Go Playground)
Example shows how to reflect over a slice of struct type values that are stored inside an interface value.
Slices (Go Playground)
Example shows how to reflect over a map of struct type values that are stored inside an interface value.
Maps (Go Playground)
Example shows how to reflect over a struct type pointer that is stored inside an interface value.
Pointers (Go Playground)
Example shows how to inspect a structs fields and display the field name, type and value.
Struct Types (Go Playground)
Example shows how to use reflection to decode an integer.
Integers (Go Playground)
All material is licensed under the Apache License Version 2.0, June 2016.