rnotify

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 3 Imported by: 0

README

rnotify

Build Status

rnotify is a wrapper of fsnotify, supports recursive directory watching on Go.

Supported Platforms

Linux, Windows and macOS.

Usage

package main

import (
	"log"

	"github.com/fsnotify/fsnotify"
	"github.com/y-yagi/rnotify"
)

func main() {
	watcher, err := rnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	done := make(chan bool)

	go func() {
		for {
			select {
			case event, ok := <-watcher.Events:
				if !ok {
					return
				}
				log.Println("event:", event)
				// `Op` is the same as `fsnotify.Op`.
				if event.Op&fsnotify.Write == fsnotify.Write {
					log.Println("modified file:", event.Name)
				}
			case err, ok := <-watcher.Errors:
				if !ok {
					return
				}
				log.Println("error:", err)
			}
		}
	}()

	err = watcher.Add("/tmp/foo")
	if err != nil {
		log.Fatal(err)
	}

	<-done
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

type Watcher struct {
	Events chan fsnotify.Event
	Errors chan error
	// contains filtered or unexported fields
}

Watcher watches files and directories, delivering events to a channel.

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher builds a new watcher.

func (*Watcher) Add

func (w *Watcher) Add(name string) error

Add starts watching the directory (recursively).

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops watching.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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