Last active
February 7, 2020 10:14
-
-
Save burakolgun/b4ce796cc08778e01a4762657f86dee5 to your computer and use it in GitHub Desktop.
csv reader in Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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