observer

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 3 Imported by: 0

README

Housekeeper

A tiny wrapper to create fsnotify recursive watchers with a framework like look and higher abstraction level sintax

Example usage

package main

import (
	"log"

	"github.com/gustapinto/housekeeper/observer"
	"github.com/fsnotify/fsnotify"
)

type DotObserver struct{}

func (o *DotObserver) HandleEvent(event fsnotify.Event) {
	switch event.Op {
		case fsnotify.Create:
			log.Print("Created: ", event.Name)
	}
}

func (o *DotObserver) HandleError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	observer.Observe(".", &DotObserver{})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Observe

func Observe(path string, observer Observer)

Observe Recursive watch a single root path and dispatch Observer handlers

func ObserveMultiple

func ObserveMultiple(paths []string, observer Observer)

ObserveMultiple Recursive watch multiple root paths and dispatch Observer handlers

Types

type Observer

type Observer interface {
	// HandleEvent handles fsnotify events
	HandleEvent(fsnotify.Event)
	// HandleError handles fsnotify event errors
	HandleError(error)
}

Observer is the basic interface used on housekeeper functions

Jump to

Keyboard shortcuts

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