You can use a bytes.Buffer to create a single csv.Reader and write the log lines into that buffer. The code will look roughly like this https://play.golang.org/p/gbCPwSsx5gy . However, depending on the implementation of strings.Reader and the level of optimization the Go compiler does, your approach of creating a new csv.Reader for every iteration might actually be faster and consume less memory than my code.
Greetings all, I have a channel of 'string', where each item is a single CSV log line that I want to convert to columns using "encoding/csv" Currently, I am creating a new csv.Reader at each iteration for each item, which is much more work than it needs to be. <snip> for i := range feederChan { r := csv.NewReader(strings.NewReader(i)) a := r.Read() // Do stuff with a // ... } </snip> I would really appreciate sharing with me if there's a way to iterate through a 'chan string' using 'csv.Reader()' without the need to create a new Reader for each item. Thanks. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com<mailto:golang-nuts+unsubscr...@googlegroups.com>. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.