Created
July 9, 2020 08:24
-
-
Save pomkine/da7f8d33c243ffc55dc7259304dcb945 to your computer and use it in GitHub Desktop.
Node-like csv channeled read
This file contains 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
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