Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created August 8, 2012 22:09
Show Gist options
  • Save leejarvis/3299291 to your computer and use it in GitHub Desktop.
Save leejarvis/3299291 to your computer and use it in GitHub Desktop.
package main
import (
"io"
"os"
"fmt"
"bufio"
)
func printlines(linechannel chan string) {
for {
fmt.Printf("'%s'\n", <- linechannel)
}
}
func readlines(in io.Reader, linechannel chan string) {
r := bufio.NewReader(in)
for {
line, _, err := r.ReadLine()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
linechannel <- string(line)
}
}
func main() {
linechannel := make(chan string)
go readlines(os.Stdin, linechannel)
printlines(linechannel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment