These steps cover writing and running your application:
- From your terminal/console application, create a new directory called chapter1/csvformat.
- Navigate to this directory.
- 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!
- 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 ...