Created
July 15, 2021 14:24
-
-
Save CodyKochmann/c54a02f8ff7dd12ef99735df6d71ae9e to your computer and use it in GitHub Desktop.
iterate stdin lines in golang
This file contains hidden or 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
| // 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