Skip to content

candysmurf/GoReflectionTalk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reflection - Standard Library

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

Links

http://blog.golang.org/laws-of-reflection

Code Review

Basics

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)

Interfaces

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)

Inspection / Decoding

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.