watch

package
v0.0.0-...-f2b1b04 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(Op, string)

Handler is a pointer to handler function that users of 'watch' package can register. It will be called on the event of any operation, 'op', on the watched files, 'fileName'.

type Op

type Op uint32

Op represents the file-operations to watch for. E.g., create, write, remove, rename, etc.

const (
	// Create represents the event when a file is created in watched
	// directory.
	Create Op = iota

	// Write represents the event when a watched file is written to.
	Write

	// Remove represents the event when a watched file is deleted.
	Remove

	// Rename represents the event when a watched file is renamed.
	Rename

	// Chmod represents the event when a watched file's premissions are
	// changed.
	Chmod

	// Tbi represents the events that are yet to be supported.
	Tbi
)

func (Op) Name

func (op Op) Name() string

Name returns the human-redable name for Op.

type Watch

type Watch struct {
	// Directories to watch.
	Dirs []string

	// Commands to exectue on watched files.
	Cmds []string

	// Regex to apply to filter watched file names.
	Regex string

	// Watch directories recursively?
	Recursive bool

	// HandlerCB function to call on file-change events.
	HandlerCB Handler
	// contains filtered or unexported fields
}

Watch represents watcher configuration: dirctories, commands to execute, file types, etc.

func New

func New(
	dirs, cmds []string,
	regex string,
	recursive bool,
	handler Handler) *Watch

New instantiates a new Watch struct.

func (*Watch) Setup

func (w *Watch) Setup() error

Setup sets up a watcher on a directory for given set of files.

func (*Watch) Start

func (w *Watch) Start() error

Start starts watching the configured directories via Setup().

Jump to

Keyboard shortcuts

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