Created
November 20, 2018 19:22
-
-
Save powerslacker/6eba6498313642512ca0b966ad6c9798 to your computer and use it in GitHub Desktop.
golang scan from stdin in a loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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