Skip to content

Instantly share code, notes, and snippets.

@johnwesonga
Last active August 29, 2015 13:56
Show Gist options
  • Save johnwesonga/9133337 to your computer and use it in GitHub Desktop.
Save johnwesonga/9133337 to your computer and use it in GitHub Desktop.
Read a CSV file, skipping the headers
package main
import (
"encoding/csv"
"fmt"
_ "io"
"os"
)
func checkCsv() {
file, err := os.Open("names.txt")
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
reader := csv.NewReader(file)
records, err := reader.ReadAll()
// skip the header row
for _, r := range records[1:] {
fmt.Println("account ", r[0]) // record has the type []string
}
}
func main() {
checkCsv()
}
name, age
john, 21
peter, 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment