Skip to content

wilhelm-murdoch/go-watcher

Repository files navigation

Watcher

CI Status GoDoc Go report Stability: Experimental

A no-nonsense wrapper around the fsnotify package.

Install

$ go get github.com/wilhelm-murdoch/go-watcher

Reference

Function New

  • func New() (*Watcher, error) #
  • watcher.go:24:31 #

New creates a new instance of a Watcher struct.

Function AddPath

  • func (w *Watcher) AddPath(path string) error #
  • watcher.go:35:37 #

AddFile adds a single valid file to the current Watcher instance and returns an error if the file is not valid.

Function WalkPath

  • func (w *Watcher) WalkPath(path string) error #
  • watcher.go:41:55 #

AddDir will recursively walk the specified directory tree and add all valid files to the current watcher instance for monitoring.

Function AddGlob

  • func (w *Watcher) AddGlob(pattern string) error #
  • watcher.go:59:70 #

AddGlob will monitor the specified "glob" pattern and add all valid files to the current watcher instance for monitoring.

Function On

  • func (w *Watcher) On(event fsnotify.Op, f func(fsnotify.Event, os.FileInfo, error) error) error #
  • watcher.go:75:94 #

On fires off an assigned callback for each event type. Only specified events are supported and all will return either nil or an error. Every watcher instance exits when it first encounters an error.

Function All

  • func (w *Watcher) All(f func(fsnotify.Event, os.FileInfo, error) error) #
  • watcher.go:97:100 #

All will fire off the specified callback on any supported fsnotify event.

Function Watch

  • func (w *Watcher) Watch() error #
  • watcher.go:150:195 #

Watch creates a new errgroup instance and monitors for changes to any of the specified files. All supported event types will fire off specified callbacks if available. This method exits on the first encountered error.

package main

import (
  "fmt"
  "strings"

  "github.com/wilhelm-murdoch/go-play"
)

func main() {
    
}

Function List

  • func (w *Watcher) List() []string #
  • watcher.go:200:202 #

List is a wrapper around fsnotify.Watchlist(). It returns a list of strings representing all files and directories currently monitored instance of fsnotify.

Function Done

  • func (w *Watcher) Done() #
  • watcher.go:206:208 #

Done signals a blocking channel that processing is complete and that we can safely exit the current watcher instance.

Documentation generated by Gadget.

License

Copyright © 2022 Wilhelm Murdoch.

This project is MIT licensed.