watch

package
v0.0.0-...-a6e58f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTailShutdown = errors.New("tail: shutdown")
)

Functions

func MyOpenFile

func MyOpenFile(name string) (file *os.File, err error)

Types

type Event

type Event struct {
	Name string
	Op   Op
}

Event describes a file change that affects `Name`

type Op

type Op uint32

Op describes a file operation on a watched object. In addition to the fsnotify events, an op mask of DirChild indicates that the event occurred in a watched directory rather than for a watched file itself.

const (
	Create Op = 1 << iota
	Write
	Remove
	Rename
	Chmod
	DirChild
)

func (Op) String

func (op Op) String() string

type Shutdown

type Shutdown interface {
	// Waits for a close event.
	Dying() <-chan struct{}

	// Kill the application, which triggers all waiters on shutdown.Dying()
	// to receive a close event.
	Kill(error)
}

Shutdown is an interface that provides a safe shutdown mechansim. The interface is compatible with tomb.Tomb.

Most channel operations should include a select on Shutdown.Dying() inorder to cleanly exit:

select {
  case <-shutdown.Dying():
    return
}

func NewShutdown

func NewShutdown() Shutdown

NewShutdown creates a shutdown object which encapsulates a single channel used to signal that the process is terminating.

type Tail

type Tail struct {
	Filename string
	// contains filtered or unexported fields
}

Tail maintains a tail-capable file buffer.

func TailFile

func TailFile(filename string) (*Tail, error)

func (*Tail) Close

func (t *Tail) Close()

func (*Tail) ProcessLines

func (t *Tail) ProcessLines(process func(line string) error) error

func (*Tail) ReadLines

func (t *Tail) ReadLines() ([]string, error)

Read all available lines from the file, and advance the position of the Tail.

func (*Tail) SendLines

func (t *Tail) SendLines(lines chan string, shutdown Shutdown) error

Send all available lines from the file, and advance the position of the Tail.

type Watcher

type Watcher struct {
	Events chan Event
	// contains filtered or unexported fields
}

Watcher watches a directory or file and guards against multiple watching events by tracking the registered set, which fsnotify does not do.

func MakeWatcher

func MakeWatcher() *Watcher

func (*Watcher) AddWatch

func (w *Watcher) AddWatch(fname string) error

AddWatch adds a watch to the watcher, if it is not already present.

func (*Watcher) Close

func (w *Watcher) Close()

Close watcher related resources.

func (*Watcher) RemoveWatch

func (w *Watcher) RemoveWatch(fname string) error

RemoveWatch removes a watch from the watcher, unless it is not already present.

func (*Watcher) RunLoop

func (w *Watcher) RunLoop(shutdown Shutdown)

RunLoop is the main watcher run loop; typically this is used inside a go routine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL