diff options
| author | Joseph Richey <joerichey@google.com> | 2017-07-17 15:12:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-17 15:12:28 -0700 |
| commit | 6f32bbc8bf51d615ef23ed37aa40910ec23cd587 (patch) | |
| tree | d97df4ac65a22333570a2b40098b721785574c0d /util | |
| parent | 4d6827a49491e941ea535178789b29e4c6b6d51f (diff) | |
| parent | f03dc9e84eea127f0efc3db21375abbafa78ce59 (diff) | |
Merge pull request #20 from google/fix
Refactor ReadLine functions
Diffstat (limited to 'util')
| -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() +} |