Skip to content

Instantly share code, notes, and snippets.

@burakolgun
Last active February 7, 2020 10:14
Show Gist options
  • Save burakolgun/b4ce796cc08778e01a4762657f86dee5 to your computer and use it in GitHub Desktop.
Save burakolgun/b4ce796cc08778e01a4762657f86dee5 to your computer and use it in GitHub Desktop.
csv reader in Golang
package main
import (
"encoding/csv"
"fmt"
"log"
"io"
)
func main() {
csvfile, err := os.Open("test.csv")
if err != nil {
log.Fatal("Couldn't open the csv file", err)
}
// Parse the file
r := csv.NewReader(csvfile)
// Iterate through the records
for {
// Read each record from csv
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
fmt.Printf("column0: %s column1 %s column2: %s \n", record[0], record[1], record[2])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment