June 2017
Intermediate to advanced
400 pages
10h 32m
English
This recipe demonstrates casting between types by wrapping them in a new type, using the strconv package, and by using interface reflection. These methods allow Go developer to quickly convert between various abstract Go types. will both reveal errors during compilation, but reflection can be more tricky. If you reflect incorrectly to an unsupported type, you'll cause a panic. Switching on type is a way to generalize and is also demonstrated in this recipe.
Conversion becomes important for packages such as math, which operate on float64 exclusively.
Read now
Unlock full access