Important Characteristics of Go: Getting User Input

Let’s learn how to get user input and how to read from standard input in Go.

Getting user input is an important part of every program. This lesson presents two ways of getting user input, which are:

  • Reading from standard input.

  • Using the command-line arguments of the program.

Reading from standard input

The fmt.Scanln() function can help us read user input while the program is already running and store it to a string variable, which is passed as a pointer to fmt.Scanln(). The fmt package contains additional functions for reading user input from the console (os.Stdin), from files, or from argument lists.

Let's try our code

The following program input.go illustrates reading from standard input:

Get hands-on with 1200+ tech skills courses.