watcher

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 7 Imported by: 0

README

Watcher

CI Status GoDoc Go report

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.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

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

Watcher represents a wrapper around `fsnotify` complete with support for its own callbacks for all supported event types.

func New

func New() (*Watcher, error)

New creates a new instance of a Watcher struct.

func (*Watcher) AddGlob

func (w *Watcher) AddGlob(pattern string) error

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

func (*Watcher) AddPath added in v0.0.2

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

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

func (*Watcher) All

func (w *Watcher) All(f func(fsnotify.Event, os.FileInfo, error) error)

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

func (*Watcher) Done

func (w *Watcher) Done()

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

func (*Watcher) List added in v0.0.2

func (w *Watcher) List() []string

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

func (*Watcher) On

func (w *Watcher) On(event fsnotify.Op, f func(fsnotify.Event, os.FileInfo, error) error) error

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.

func (*Watcher) WalkPath added in v0.0.2

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

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

func (*Watcher) Watch

func (w *Watcher) Watch() error

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.

Example (All)
package main

import ()

func main() {

}
Output:

Jump to

Keyboard shortcuts

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