How it works...
This recipe gave examples of using a TOML, YAML, and JSON parser to both write raw data to a go struct and read data out of it and into the corresponding format. Like with the recipes in Chapter 1, I/O and File Systems, we see how common it is to quickly switch between []byte, string, bytes.Buffer, and other I/O interfaces.
The encoding/json package is the most comprehensive in providing encoding, marshaling, and other methods to work with the JSON format. We abstracted these away with our ToFormat functions, and it would be very simple to attach multiple methods such as this to use a single struct that can quickly be converted to or from any of these types.
This section also used and touched upon struct tags and their use. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access