Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active January 1, 2022 18:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miguelmota/6310b4aae11b095a7f68d458ae5e9cf9 to your computer and use it in GitHub Desktop.
Save miguelmota/6310b4aae11b095a7f68d458ae5e9cf9 to your computer and use it in GitHub Desktop.
Golang stdin read line example
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter name: ")
text, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
fmt.Printf("Your name is: %s\n", text)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment