Created
January 18, 2016 21:43
-
-
Save lmas/d8e7617c55a672de561d to your computer and use it in GitHub Desktop.
stding.go - Read a Go string from STDIN
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" | |
"io" | |
"os" | |
) | |
func main() { | |
bufio := bufio.NewReader(os.Stdin) | |
for { | |
fmt.Printf("> ") | |
msg, e := bufio.ReadString('\n') | |
if e != nil { | |
if e == io.EOF { | |
os.Exit(0) | |
} | |
fmt.Println("Error:", e) | |
} | |
fmt.Println(msg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment