Skip to content

Instantly share code, notes, and snippets.

@philangist
Created May 15, 2018 08:49
Show Gist options
  • Save philangist/3f214657a7fe4bef0b1cb02b8e564c11 to your computer and use it in GitHub Desktop.
Save philangist/3f214657a7fe4bef0b1cb02b8e564c11 to your computer and use it in GitHub Desktop.
type CSVParser struct {
scanner *bufio.Scanner
Validator func([]string) bool
Output chan []string
}
func ReaderCSVParser(reader io.Reader) *CSVParser {
return &CSVParser{
bufio.NewScanner(reader),
ValidateCSVLine,
make(chan []string),
}
}
func (c *CSVParser) Parse (dest chan []string){
for c.scanner.Scan() {
line := strings.Split(c.scanner.Text(), ",")
valid := c.Validator(line)
if !valid {
continue
}
c.Output <- line
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment