Reading from “standard input” is really useful if you are making a command-line application and require user input.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
package main

import (
    "bufio"
    "os"
    "fmt"
)

func main() {
    reader := bufio.NewReader(os.Stdin)
    s, _ := reader.ReadString('\n')
    fmt.Printf(s)
}

First setup a new bufio reader, then use ReadString function, with a default wait character, which we have set to a newline (\n).

The application will pause at this point and wait for user input before proceeding.