From f4de90f84d0ead2761ae3ae47d91de2977fe374b Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Mon, 17 Jul 2017 15:01:38 -0700 Subject: [PATCH] util: Move line reading into common package --- util/util.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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() +} -- 2.39.5