Go: Read from stdin

Use a bufio.Scanner to read one line at a time from standard input:

scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
	fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
	log.Println(err)
}

Comments

Be the first to comment!