Configuration using TOML, YAML, and JSON
There are many configuration formats that Go, with the use of third-party libraries, has support for. Three of the most popular data formats are TOML, YAML, and JSON. Go can support JSON out of the box, and the others have clues on how to marshal/unmarshal or encode/decode data for these formats. The formats have many benefits beyond configuration, but this chapter will largely focus on converting a Go struct in the form of a configuration struct. This recipe will explore basic input and output using these formats.
These formats also provide an interface by which Go and applications written in other languages can share the same configuration. There are also a number of tools that deal with these formats and simplify working with them.
Getting ready
Configure your environment according to these steps:
- Refer to the Getting ready section's steps in the Using command-line flags recipe.
- Run the
go get github.com/BurntSushi/toml
command. - Run the
go get github...