diff options
| author | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-07-17 15:01:38 -0700 |
|---|---|---|
| committer | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-07-17 15:01:38 -0700 |
| commit | f4de90f84d0ead2761ae3ae47d91de2977fe374b (patch) | |
| tree | f0d14fd5b5cb0262c790a1a5260b2eacb8dc2cfe | |
| parent | 4d6827a49491e941ea535178789b29e4c6b6d51f (diff) | |
util: Move line reading into common package
| -rw-r--r-- | util/util.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go index 2f20151..32e5c06 100644 --- a/util/util.go +++ b/util/util.go @@ -24,6 +24,8 @@ package util import ( + "bufio" + "os" "unsafe" ) @@ -72,3 +74,11 @@ func MinInt64(a, b int64) int64 { } return b } + +// ReadLine returns a line of input from standard input. An empty string is +// returned if the user didn't insert anything or on error. +func ReadLine() (string, error) { + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + return scanner.Text(), scanner.Err() +} |