Go: "tail -f"-like generator <p>I had this convenient function in Python:</p> <pre><code>def follow(path): with open(self.path) as lines: lines.seek(0, 2) # seek to EOF while True: line = lines.readline() if not line: time.sleep(0.1) continue yield line </code></pre> <p>It does something similar to UNIX <code>tail -f</code>: you get last lines of a file as they come. It's convenient because you can get the generator <em>without blocking</em> and pass it to another function.</p> <p>Then I had to do the same thing in Go. I'm new to this language, so I'm not sure whether what I did is idiomatic/correct enough for Go. </p> <p>Here is the code:</p> <pre><code>func Follow(fileName string) chan string { out_chan := make(chan string) file, err := os.Open(fileName) if err != nil { log.Fatal(err) } file.Seek(0, os.SEEK_END) bf := bufio.NewReader(file) go func() { for { line, _, _ := bf.ReadLine() if len(line) == 0 { time.Sleep(10 * time.Millisecond) } else { out_chan &lt;- string(line) } } defer file.Close() close(out_chan) }() return out_chan } </code></pre> <p>Is there any cleaner way to do this in Go? I have a feeling that using an asynchronous call for such a thing is an overkill, and it really bothers me.</p>