fsw

package
v1.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 8 Imported by: 1

README

Pango FSWatch

This is a wrapper around https://github.com/fsnotify/fsnotify instead of only monitoring a top level folder, it allows you to monitor all folders underneath the folder you specify.

Install:
go get github.com/askasoft/pango
Example:

(error handling omitted to improve readability)

import (
	"fmt"
	github.com/askasoft/pango/fsw
)

// works exactly like fsnotify and implements the same API.
watcher, err := fsw.NewFileWatcher()

// watch recursive and recieve events with callback function
watcher.AddRecursive("watchdir", fsw.OpALL, func(path string, op fsw.Op) {
	fmt.Printf("%s %s\n", path, op)
})

// start watch go-routine
watcher.Start()

Documentation

Index

Constants

View Source
const (
	// OpNone none operation
	OpNone = Op(0)

	// OpCreate create operation
	OpCreate = Op(fsnotify.Create)

	// OpWrite write operation
	OpWrite = Op(fsnotify.Write)

	// OpRemove remove operation
	OpRemove = Op(fsnotify.Remove)

	// OpRename rename operation
	OpRename = Op(fsnotify.Rename)

	// OpChmod chmod operation
	OpChmod = Op(fsnotify.Chmod)

	// OpModifies modifies operations (OpCreate | OpWrite | OpRemove | OpRename)
	OpModifies = OpCreate | OpWrite | OpRemove | OpRename

	// OpALL all operations
	OpALL = Op(0xFFFFFFFF)
)

Variables

This section is empty.

Functions

func Add

func Add(path string, op Op, callback func(string, Op)) error

Add add a file to watch on specified operation op occurred

func AddRecursive

func AddRecursive(path string, op Op, cb func(string, Op)) error

AddRecursive add files and all sub-directories under the path to watch

func Remove

func Remove(path string) error

Remove stop watching the file

func RemoveRecursive

func RemoveRecursive(path string) error

RemoveRecursive stops watching the directory and all sub-directories.

func Start

func Start() (err error)

Start start file watching go-routine

func Stop

func Stop() (err error)

Stop stop file watching go-routine

Types

type FileWatcher

type FileWatcher struct {
	Delay  time.Duration
	Logger log.Logger // Error logger
	// contains filtered or unexported fields
}

FileWatcher struct for file watching

func Default

func Default() *FileWatcher

Default returns the default FileWatcher instance used by the package-level functions.

func NewFileWatcher

func NewFileWatcher() *FileWatcher

NewFileWatcher create a FileWatcher

func (*FileWatcher) Add

func (fw *FileWatcher) Add(path string, op Op, callback func(string, Op)) error

Add add a file to watch on specified operation op occurred

func (*FileWatcher) AddRecursive

func (fw *FileWatcher) AddRecursive(path string, op Op, cb func(string, Op)) error

AddRecursive add files and all sub-directories under the path to watch

func (*FileWatcher) Remove

func (fw *FileWatcher) Remove(path string) error

Remove stop watching the file

func (*FileWatcher) RemoveRecursive

func (fw *FileWatcher) RemoveRecursive(path string) error

RemoveRecursive stops watching the directory and all sub-directories.

func (*FileWatcher) Start

func (fw *FileWatcher) Start() (err error)

Start start file watching go-routine

func (*FileWatcher) Stop

func (fw *FileWatcher) Stop() (err error)

Stop stop file watching go-routine

type Op

type Op = fsnotify.Op

Op describes a set of file operations.

Jump to

Keyboard shortcuts

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