Created
January 13, 2020 21:26
-
-
Save topherPedersen/fa3f5a12fd34a818ca02d5bcc47b9f43 to your computer and use it in GitHub Desktop.
Command Line User Input in Golang
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
// 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