mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
util/lineread: add docs to Reader
In particular, point out how to stop reading and detect it on the other side. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
1ebbaaaebb
commit
b65eee0745
@ -22,6 +22,11 @@ func File(name string, fn func(line []byte) error) error {
|
|||||||
return Reader(f, fn)
|
return Reader(f, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reader calls fn for each line.
|
||||||
|
// If fn returns an error, Reader stops reading and returns that error.
|
||||||
|
// Reader may also return errors encountered reading and parsing from r.
|
||||||
|
// To stop reading early, use a sentinel "stop" error value and ignore
|
||||||
|
// it when returned from Reader.
|
||||||
func Reader(r io.Reader, fn func(line []byte) error) error {
|
func Reader(r io.Reader, fn func(line []byte) error) error {
|
||||||
bs := bufio.NewScanner(r)
|
bs := bufio.NewScanner(r)
|
||||||
for bs.Scan() {
|
for bs.Scan() {
|
||||||
|
Loading…
Reference in New Issue
Block a user