How to do it...

These steps cover writing and running your application:

  1. From your terminal/console application, create a new directory called chapter2/confformat and navigate to that directory.
  2. Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter2/confformat, or use this as an exercise to write some of your own code!
  3. Create a file called toml.go with the following contents:
        package confformat        import (            "bytes"            "github.com/BurntSushi/toml"        )        // TOMLData is our common data struct        // with TOML struct tags        type TOMLData struct {            Name string `toml:"name"`            Age int `toml:"age"`        }        // ToTOML dumps the TOMLData struct to        // a TOML format bytes.Buffer        func (t *TOMLData) ToTOML() (*bytes.Buffer, error) {            b := &bytes.Buffer{}

Get Go Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.