Skip to content

Instantly share code, notes, and snippets.

@powerslacker
Created November 20, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save powerslacker/6eba6498313642512ca0b966ad6c9798 to your computer and use it in GitHub Desktop.
Save powerslacker/6eba6498313642512ca0b966ad6c9798 to your computer and use it in GitHub Desktop.
golang scan from stdin in a loop
package main
import (
"bufio"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
for {
if scanner.Scan() {
switch scanner.Text() {
case "hi":
println("hello")
case "exit":
os.Exit(0)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment