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, 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.