gorph

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 9 Imported by: 1

README

gorph

gorph is an efficient recursive file watcher that accepts double-star globs.

In builds on fsnotify providing sorely needed recursive functionality while retaining it's excellent cross-platform support and stability.

Value Proposition

There does not appear to be a good alternative for this. The goal is:

  • efficient and flexible globbing
  • good cross-platform support
  • simple, intuitive API
  • usable as a package or a binary
Watch Tree

Why Gorph

The name was chosen haphzaradly to seem like "go recursive file watcher".

Using it as a binary

Install and use like so:

$ go install github.com/sean9999/go-fsnotify-recursively/cmd/gorph@latest
$ gorph # watch everything recursively in current directory
$ gorph ~/Videos/**/*.mov # watch Videos recursively for anything with a .mov extension

Using as a package

package main
import (
    gorph "github.com/sean9999/go-fsnotify-recursively"
)

func main(){

    //  watch for any text file under ./testdata/
    //  double-stars mean search recursively
    watcher := gorp.New("testdata/**/*.txt")

    //  two channels
    events, errs := watcher.Listen()

    ...    
    

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDir

func IsDir(filesystem fs.FS, path string) bool

Types

type Gorph

type Gorph interface {
	fs.GlobFS
	Root() string
	Pattern() string
	Walk() ([]string, error)
	Folders() []string
	Children(path string) ([]string, error)
	Listen() (chan GorphEvent, chan error)
	Close() error
	WatchList() []string
}

Gorph is a file system that can do globbing

func New

func New(globPattern string) (Gorph, error)

New constructs a new Gorph

func NewWithFs

func NewWithFs(root string, pattern string, backingFs fs.FS) (Gorph, error)

NewWithFs allows you to pass in a custom fs.FS. Useful for testing

type GorphEvent

type GorphEvent struct {
	NotifyEvent *fsnotify.Event
	Op          GorphOp
	Path        string
	Matches     bool
}

func NotifyToGorphEvent

func NotifyToGorphEvent(g *gorph, fevent *fsnotify.Event) GorphEvent

func (GorphEvent) String

func (gevent GorphEvent) String() string

type GorphOp

type GorphOp uint8
const (
	UndefinedOp GorphOp = iota
	FsNotifyEvent
	FolderAdded
	FolderRemoved
	FolderRenamed
	FolderMoved
	FolderModified
	FolderUnknown
)

func (GorphOp) String

func (gop GorphOp) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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