Version: v2.0.0+incompatible Latest Latest

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

Go to latest
Published: Apr 11, 2015 License: MIT Imports: 8 Imported by: 0



Package watcher implements filesystem notification,.



View Source
const (
	// NONE means no event, initial state.
	NONE = iota
	// CREATED means file was created.
	// DELETED means file was deleted.
	// MODIFIED means file was modified.
	// PERM means changed permissions
	// NOEXIST means file does not exist.
	// NOPERM means no permissions for the file (see const block comment).
	// INVALID means any type of error not represented above.
View Source
const (
	// IgnoreThresholdRange is the amount of time in ns to ignore when
	// receiving watch events for the same file
	IgnoreThresholdRange = 50 * 1000000 // convert to ms


This section is empty.


func DefaultIgnorePathFn

func DefaultIgnorePathFn(path string) bool

DefaultIgnorePathFn checks whether a path is ignored. Currently defaults to hidden files on *nix systems, ie they start with a ".".

func SetWatchDelay

func SetWatchDelay(delay time.Duration)

SetWatchDelay sets the watch delay


type FileEvent

type FileEvent struct {
	Event    int
	Path     string
	UnixNano int64

FileEvent is a wrapper around

func (*FileEvent) String added in v1.3.0

func (fe *FileEvent) String() string

String returns an eye friendly version of this event.

type Watcher

type Watcher struct {
	Event chan *FileEvent
	Error chan error
	//default ignore all file start with "."
	IgnorePathFn func(path string) bool
	//default is nil,if is nil ,error send through Error chan,if is not nil,error handle by this func
	ErrorHandler func(err error)
	// contains filtered or unexported fields

Watcher is a wrapper around which adds some additional features:

- recursive directory watch - buffer to even chan - even time

Original work from

func NewWatcher

func NewWatcher(bufferSize int) (watcher *Watcher, err error)

NewWatcher creates an instance of watcher.

func (*Watcher) Close

func (w *Watcher) Close() error

Close closes the watcher channels.

func (*Watcher) GetErrorChan

func (w *Watcher) GetErrorChan() chan error

GetErrorChan gets error chan.

func (*Watcher) GetEventChan

func (w *Watcher) GetEventChan() chan *FileEvent

GetEventChan gets event chan.

func (*Watcher) SetIgnorePathFn

func (w *Watcher) SetIgnorePathFn(fn func(string) bool)

SetIgnorePathFn sets the function which determines if a path should be skipped when watching.

func (*Watcher) Start

func (w *Watcher) Start()

Start starts the watcher

func (*Watcher) WatchRecursive

func (w *Watcher) WatchRecursive(path string) error

WatchRecursive watches a directory recursively. If a dir is created within directory it is also watched.


Path Synopsis
Package fswatch provides simple UNIX file system watching in Go.
Package fswatch provides simple UNIX file system watching in Go.
clinotify provides an example file system watching command line app.
clinotify provides an example file system watching command line app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL