Use scanner instead of buffer read line

Supported in Go 1.1 http://golang.org/pkg/bufio/#Scanner
This commit is contained in:
bdd 2014-08-25 11:58:14 -04:00
parent 56cf1e6faa
commit 6da9a2d49d
1 changed files with 6 additions and 7 deletions

View File

@ -245,12 +245,11 @@ func retryFunc(timeout time.Duration, f func() error) error {
// of a remote command to log output for users.
func streamLogs(r io.ReadCloser, name string) {
defer r.Close()
bufR := bufio.NewReader(r)
for {
line, err := bufR.ReadString('\n')
if err != nil {
return
}
log.Printf("remote-exec: %s: %s", name, line)
scanner := bufio.NewScanner(r)
for scanner.Scan() {
log.Printf("remote-exec: %s: %s", name, scanner.Text())
}
if err := scanner.Err(); err != nil {
return
}
}