Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iterate stdin lines in golang
// by: Cody Kochmann
// this iterates stdin lines to a golang channel
package main
import (
"os"
"bufio"
)
func IterStdin() <-chan string {
out := make(chan string)
go func() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
out <- scanner.Text() // Println will add back the final '\n'
}
}()
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment