Skip to content

Instantly share code, notes, and snippets.

@r00tvvm
Forked from miguelmota/stdin_example.go
Created January 1, 2022 18:01
Show Gist options
  • Select an option

  • Save r00tvvm/fc5ee2d3413a21f1de7c4a5ae1af4ca8 to your computer and use it in GitHub Desktop.

Select an option

Save r00tvvm/fc5ee2d3413a21f1de7c4a5ae1af4ca8 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