Reading an integer from standard input

http://golang.org/pkg/fmt/#Scanf

All the included libraries in Go are well documented.

That being said, I believe

func main() {
    var i int
    _, err := fmt.Scanf("%d", &i)
}

does the trick


An alternative that can be a bit more concise is to just use fmt.Scan:

package main

import "fmt"

func main() {
    var i int
    fmt.Scan(&i)
    fmt.Println("read number", i, "from stdin")
}

This uses reflection on the type of the argument to discover how the input should be parsed.

http://golang.org/pkg/fmt/#Scan