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.

Revisions

  1. burakolgun revised this gist Feb 7, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.go
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ import (
    )

    func main() {
    csvfile, err := os.Open("test-csv.csv")
    csvfile, err := os.Open("test.csv")
    if err != nil {
    log.Fatal("Couldn't open the csv file", err)
    }
  2. burakolgun created this gist Feb 7, 2020.
    31 changes: 31 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    package main

    import (
    "encoding/csv"
    "fmt"
    "log"
    "io"
    )

    func main() {
    csvfile, err := os.Open("test-csv.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])
    }
    }