Golang : Read input from console line

Ok, this is another tutorial on how to read input from console in Golang. It uses the bufio.NewReader() function and accept input from standard input via os.Stdin. Simple and straight forward example below:

 package main

 import (

 func main() {
 consolereader := bufio.NewReader(os.Stdin)
 fmt.Print("Enter your name : ")

 input, err := consolereader.ReadString('\n') // this will prompt the user for input

 if err != nil {


Output :

Enter your name : BooBooBoy



  See also : Golang : Get input from keyboard

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.