Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Created January 13, 2020 21:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherPedersen/fa3f5a12fd34a818ca02d5bcc47b9f43 to your computer and use it in GitHub Desktop.
Save topherPedersen/fa3f5a12fd34a818ca02d5bcc47b9f43 to your computer and use it in GitHub Desktop.
Command Line User Input in Golang
// Command Line User Input in Golang
// REFERENCE: https://stackoverflow.com/questions/20895552/how-to-read-from-standard-input-in-the-console
package main
import (
"fmt"
"bufio"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print(">>> ")
userInput, _ := reader.ReadString('\n')
fmt.Println(userInput)
fmt.Print(">>> ")
userInput2, _ := reader.ReadString('\n')
fmt.Println(userInput2)
fmt.Print(">>> ")
userInput3, _ := reader.ReadString('\n')
fmt.Println(userInput3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment