Created
May 15, 2018 08:49
-
-
Save philangist/3f214657a7fe4bef0b1cb02b8e564c11 to your computer and use it in GitHub Desktop.
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
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