Skip to content

Instantly share code, notes, and snippets.

@lmas
Created January 18, 2016 21:43
Show Gist options
  • Save lmas/d8e7617c55a672de561d to your computer and use it in GitHub Desktop.
Save lmas/d8e7617c55a672de561d to your computer and use it in GitHub Desktop.
stding.go - Read a Go string from STDIN
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