From 941cc3e3017a3a3c28e3b1b53b94dbaa0dd837e5 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 16 May 2014 18:05:11 -0700 Subject: [PATCH] refactor this part of code for upcoming change --- tail.go | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/tail.go b/tail.go index f166589..89a9474 100644 --- a/tail.go +++ b/tail.go @@ -213,31 +213,27 @@ func (tail *Tail) tailFileSync() { for { line, err := tail.readLine() - switch err { - case nil: - if true { - cooloff := !tail.sendLine(line) - if cooloff { - // Wait a second before seeking till the end of - // file when rate limit is reached. - msg := fmt.Sprintf( - "Too much log activity; waiting a second " + - "before resuming tailing") - tail.Lines <- &Line{msg, time.Now(), fmt.Errorf(msg)} - select { - case <-time.After(time.Second): - case <-tail.Dying(): - return - } - err = tail.seekEnd() - if err != nil { - tail.Kill(err) - return - } + if err == nil { + cooloff := !tail.sendLine(line) + if cooloff { + // Wait a second before seeking till the end of + // file when rate limit is reached. + msg := fmt.Sprintf( + "Too much log activity; waiting a second " + + "before resuming tailing") + tail.Lines <- &Line{msg, time.Now(), fmt.Errorf(msg)} + select { + case <-time.After(time.Second): + case <-tail.Dying(): + return + } + err = tail.seekEnd() + if err != nil { + tail.Kill(err) + return } } - case io.EOF: - // XXX: should `line` be returned at this point? + }else if err == io.EOF { if !tail.Follow { return } @@ -251,7 +247,8 @@ func (tail *Tail) tailFileSync() { } return } - default: // non-EOF error + }else { + // non-EOF error tail.Killf("Error reading %s: %s", tail.Filename, err) return }