How to do it...

These steps cover writing and running your application:

  1. From your terminal/console application, create a new directory called chapter1/csvformat.
  2. Navigate to this directory.
  3. Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter1/csvformat, or use this as an exercise to write some of your own code!

  1. Create a file called read_csv.go with the following contents:
        package csvformat                import (                "bytes"                "encoding/csv"                "fmt"                "io"                "strconv"        )                // Movie will hold our parsed CSV        type Movie struct {                Title string                Director string                Year int        }                // ReadCSV gives shows some examples of processing CSV        // that is passed in as an io.Reader        func ReadCSV(b io.Reader) ([]Movie, error) {                        r := csv.NewReader(b)         // These are ...

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.