Skip to content

Instantly share code, notes, and snippets.

@pomkine
Created July 9, 2020 08:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pomkine/da7f8d33c243ffc55dc7259304dcb945 to your computer and use it in GitHub Desktop.
Node-like csv channeled read
func processCSV(rc io.Reader) (ch chan []string) {
ch = make(chan []string, 10)
go func() {
r := csv.NewReader(rc)
if _, err := r.Read(); err != nil { //read header
log.Fatal(err)
}
defer close(ch)
for {
rec, err := r.Read()
if err != nil {
if err == io.EOF {
break
}
log.Fatal(err)
}
ch <- rec
}
}()
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment