dirwatch

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: MIT Imports: 9 Imported by: 11

README

dirwatch

For watching for changes inside a directory and all sub-directories, recursively. Uses the package fsnotify.

Documentation:

GoDoc

Sample Usage

notify := func(ev Event) {
	// processing the event ev
}

// create the watcher which excludes
// any folder along the added paths
// that matches provided pattern(s).
watcher := New(Notify(notify), Exclude("/*/*/node_modules"))
defer watcher.Stop()
watcher.Add(dir1, true)
watcher.Add(dir2, false)
watcher.Add(dir3, true)
Environment:
  • Ubuntu 18.04
  • Go 1.10.3
TODO:
  • more tests

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event added in v0.2.0

type Event struct {
	Name string
	Op   fsnotify.Op
}

Event represents a single file system notification.

type Option added in v0.4.0

type Option func(*options)

Option modifies the options.

func Exclude added in v0.4.0

func Exclude(exclude ...string) Option

Exclude sets patterns to exclude from watch.

func Logger added in v0.4.0

func Logger(logger func(args ...interface{})) Option

Logger sets the logger for the watcher.

func Notify added in v0.4.0

func Notify(notify func(Event)) Option

Notify sets the notify callback.

type Watcher added in v0.2.0

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher watches over a directory and it's sub-directories, recursively.

Example (Recursive)
Output:

4
Example (Simple)
Output:

text.txt
Example (SimpleExclude)
Output:

4

func New

func New(opt ...Option) *Watcher

New creates a new *Watcher. Excluded patterns are based on filepath.Match function patterns.

func (*Watcher) Add added in v0.3.0

func (dw *Watcher) Add(path string, recursive bool)

Add adds a path to be watched.

func (*Watcher) Stop added in v0.2.0

func (dw *Watcher) Stop()

Stop stops the watcher. Safe to be called mutiple times.

Jump to

Keyboard shortcuts

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