Go Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

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.