rnotify

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2021 License: LGPL-3.0 Imports: 9 Imported by: 1

README

rnotify

Watches a root folder and sends events whenever a file got changed in some way.

It uses fsnotify to do the heavy lifting.

rnotify has a very narrow focus. It only wants to be informed about file changes. Creating, writing, appending, renaming or discovering a file will all send the same notification.

It's recursive. It has one single root folder and it listens to all file changes inside. Some specific folders can be excluded. This will exclude all the sub tree of the matched folder.

problems

It's not really reliable. When adding folders and files in fast sucession it can happen that some events are missed because added watches take a while till they trigger events.

It can trigger extra events.

todo

  • better error handling (channel?)
  • testing on different os' (linux, osx, windows)
  • stress testing
  • ? throttle with deduplication of events

usage

import "gitlab.com/akabio/rnotify"

...

rn, err := rnotify.New("folder", []string{".git", "**/node_modules"})
if err != nil {
  ...
}

for evt := range rn.Events {
  fmt.Println(evt)
}

apidoc

https://pkg.go.dev/gitlab.com/akabio/rnotify

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Path string
}

Event notifies about a changed/created/moved file. It contains the path of the file relative to the root folder of the watcher.

func (Event) String

func (e Event) String() string

type Watcher

type Watcher struct {
	// Events is an unbuffered channel. It receives the filesystem changes as Event instances.
	// The channel will be closed when the watcher is closed with watcher.Close().
	Events chan (Event)
	// contains filtered or unexported fields
}

Watcher represents a watch from a folder recusrsively down the tree.

func New

func New(root string, exclude []string) (*Watcher, error)

New creates a new watcher instance and starts listening for filechanges.

The root parameter must be a path to the watched folder.

The exclude array contains a list of folders that are recursively excluded from the watcher. So an exclude of ".git" will not listen for any changes in the .git folder and any subdirectories. The exclude matcher syntax allows paths in the form of `root/**/dist/asset*/ba[rz]/*.gen.ts`. see (gobwas)[https://pkg.go.dev/github.com/gobwas/glob#Compile] for more details.

func (*Watcher) Close

func (w *Watcher) Close()

Close unregisters the watcher and closes the Event channel.

Jump to

Keyboard shortcuts

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