Skip to content

Commit 5c10b45

Browse files
author
Francesc Campoy
committed
moved scanning to a single goroutine
1 parent b26fb1d commit 5c10b45

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

logpipe.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ func main() {
6161

6262
// Read from Stdin and log it to Stdout and Stackdriver
6363
lines := make(chan string)
64-
s := bufio.NewScanner(io.TeeReader(os.Stdin, os.Stdout))
6564
go func() {
66-
defer close(lines)
65+
s := bufio.NewScanner(io.TeeReader(os.Stdin, os.Stdout))
6766
for s.Scan() {
6867
lines <- s.Text()
6968
}
69+
if err := s.Err(); err != nil {
70+
errc <- fmt.Errorf("could not read from std in: %v", err)
71+
}
72+
close(lines)
7073
}()
7174

7275
signals := make(chan os.Signal)
@@ -95,9 +98,5 @@ mainLoop:
9598
log.Fatalf("Failed to close client: %v", err)
9699
}
97100

98-
if err := s.Err(); err != nil {
99-
log.Fatalf("Failed to scan input: %v", err)
100-
}
101-
102101
fmt.Fprintln(os.Stderr, "Finished logging")
103102
}

0 commit comments

Comments
 (0)