Created
August 8, 2012 22:09
-
-
Save leejarvis/3299291 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
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