Documentation ¶
Overview ¶
Package recwatch provides a way to watch directories recursively, using fsnotify
Index ¶
- Variables
- func CollectFileChangeEvents(watcher *RecursiveWatcher, mut *sync.Mutex, events TimeEventMap, ...)
- func EventServer(path, allowed, eventAddr, eventPath string, refreshDuration time.Duration)
- func Flush(w http.ResponseWriter) bool
- func GenFileChangeEvents(events TimeEventMap, mut *sync.Mutex, maxAge time.Duration, allowed string) http.HandlerFunc
- func RemoveOldEvents(events *TimeEventMap, maxAge time.Duration)
- func SetVerbose(enabled bool)
- func ShouldIgnoreFile(name string) bool
- func Subfolders(path string) (paths []string)
- func WriteEvent(w http.ResponseWriter, id *uint64, message string, flush bool)
- type Event
- type RecursiveWatcher
- type TimeEventMap
Constants ¶
This section is empty.
Variables ¶
Exists checks if the given path exists, using os.Stat
var FatalExit = func(err error) { log.Fatalln(err) }
FatalExit ends the program after logging a message
var LogError = func(err error) { log.Println(err.Error()) }
LogError logs a message as an error, but does not end the program
var LogInfo = func(msg string) { log.Println(msg) }
LogInfo logs a message as information
Functions ¶
func CollectFileChangeEvents ¶
func CollectFileChangeEvents(watcher *RecursiveWatcher, mut *sync.Mutex, events TimeEventMap, maxAge time.Duration)
CollectFileChangeEvents gathers filesystem events in a way that web handle functions can use
func EventServer ¶
EventServer serves events on a dedicated port. addr is the host address ([host][:port]) The filesystem events are gathered independently of that. Allowed can be "*" or a hostname and sets a header in the SSE stream.
func Flush ¶
func Flush(w http.ResponseWriter) bool
Flush can flush the given ResponseWriter. Returns false if it wasn't an http.Flusher.
func GenFileChangeEvents ¶
func GenFileChangeEvents(events TimeEventMap, mut *sync.Mutex, maxAge time.Duration, allowed string) http.HandlerFunc
GenFileChangeEvents creates an SSE event whenever a file in the server directory changes.
Uses the following HTTP headers:
Content-Type: text/event-stream;charset=utf-8 Cache-Control: no-cache Connection: keep-alive Access-Control-Allow-Origin: (custom value)
The "Access-Control-Allow-Origin" header uses the value that is passed in the "allowed" argument.
func RemoveOldEvents ¶
func RemoveOldEvents(events *TimeEventMap, maxAge time.Duration)
RemoveOldEvents can remove old filesystem events, after a certain duration. Needs to be called within a mutex!
func SetVerbose ¶
func SetVerbose(enabled bool)
SetVerbose can be used to enable or disable logging of incoming events
func ShouldIgnoreFile ¶
ShouldIgnoreFile determines if a file should be ignored. File names that begin with "." or "_" are ignored by the go tool.
func Subfolders ¶
Subfolders returns a slice of subfolders (recursive), including the provided path
func WriteEvent ¶
func WriteEvent(w http.ResponseWriter, id *uint64, message string, flush bool)
WriteEvent writes SSE events to the given ResponseWriter. id can be nil.
Types ¶
type Event ¶
Event is a custom type, so that packages that depends on recwatch does not also have to import fstnotify
type RecursiveWatcher ¶
RecursiveWatcher keeps the data for watching files and directories
func NewRecursiveWatcher ¶
func NewRecursiveWatcher(path string) (*RecursiveWatcher, error)
NewRecursiveWatcher creates a new RecursiveWatcher. Takes a path to a directory to watch.
func (*RecursiveWatcher) AddFolder ¶
func (watcher *RecursiveWatcher) AddFolder(folder string) error
AddFolder adds a directory to watch, non-recursively