Created
March 29, 2018 01:54
-
-
Save joerx/10e75f6eba6cddf785d505f03486827a to your computer and use it in GitHub Desktop.
Read data from stdin in go
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 ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
in := os.Stdin | |
r := bufio.NewReader(in) | |
for { | |
line, err := r.ReadString('\n') | |
if err != nil { | |
break | |
} | |
fmt.Printf("> %s", line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment