January 5, 2018 - For the purpose of this article, consider the following CSV data, slightly modified from the docs for encoding/csv:
csvData := strings.NewReader(strings.Join([]string{ `first_name,last_name,username`, `"Rob","Pike",rob`, `Ken,Thompson,ken`, `"Robert","Griesemer","gri"`, }, "\n")) Here’s how you read the data, line by line, using the Reader provided in that package:
reader := csv.NewReader(csvData) for { record, err := reader.Read() if err == io.EOF { break } if err != nil { // handle the error... // break? Continue reading »