Created
November 22, 2018 16:46
-
-
Save powerman/d4d56ff4ddbf82e7a685115fde8bba1e to your computer and use it in GitHub Desktop.
Template for tail.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package tail implements behaviour of `tail -n 0 -F path`. | |
package tail | |
import ( | |
"time" | |
) | |
var ( | |
pollDelay = 200 * time.Millisecond // delay between polling to save CPU | |
pollTimeout = time.Second // how long to wait before returning os.ErrNotExist | |
) | |
// Tail is an io.ReadCloser with `tail -n 0 -F path` behaviour. | |
type Tail struct { | |
} | |
// NewTail starts tracking the file using polling. | |
// | |
// If file already exists tracking begins from the end of the file. | |
// | |
// Supported file types: usual, FIFO and symlink. | |
func NewTail(file string) *Tail { | |
panic("TODO") | |
} | |
// Read returns appended data as the file grows, keep trying to open a | |
// file if it is inaccessible, and continue reading from beginning of the | |
// file when it will became accessible (e.g. after log rotation). | |
// | |
// Returned data is not guaranteed to contain full lines of text. | |
// | |
// If Read returns any error except io.EOF, then following Read will | |
// return either some data or io.EOF. | |
// | |
// Read may return 0, nil only if len(p) == 0. | |
// | |
// Read will return io.EOF only after Close. Following Read will return | |
// io.EOF. | |
// | |
// Read must not be called from simultaneous goroutines, but Close can be | |
// called simultaneously with Read or Close. | |
func (t *Tail) Read(p []byte) (int, error) { | |
panic("TODO") | |
} | |
// Close stops tracking the file. | |
func (t *Tail) Close() error { | |
panic("TODO") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment