func readstdin(reader *bufio.Reader) string {
	text, err := reader.ReadString('\n')
	if err != nil {
		log.Fatalf("Error when reading input: %v", err)
	}
	return strings.TrimSpace(text)
}
Readstdin reads a line from stdin trimming spaces, and returns the value.
log.Fatal's if there is an error.
package util
import (
	"bufio"
	"fmt"
	"log"
	"strings"
)
func YesNo(reader *bufio.Reader) bool {
	for {
		text := readstdin(reader)
		switch text {
		case "y", "yes":
			return true
		case "n", "no":
			return false
		default:
			fmt.Printf("invalid input %q, should be [y/n]", text)
		}
	}
}