filewatcher

package module
v0.0.0-...-07aa870 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: AGPL-3.0 Imports: 6 Imported by: 1

README

FileWatcher - Go Package for File and Directory Watching

FileWatcher is a Go package that provides a file and directory watcher with callbacks for create, remove, and modify events.

Installation

To use FileWatcher in your Go project, you can install it using go get:

go get -u github.com/NIR3X/filewatcher

Usage

package main

import (
	"fmt"
	"time"
	"github.com/NIR3X/filewatcher"
)

func main() {
	// Initialize FileWatcher
	f := filewatcher.NewFileWatcher(time.Second, func(path string, isDir bool, failed func()) {
		// Callback for created files and directories
		if isDir {
			fmt.Println("created dir:", path)
		} else {
			fmt.Println("created file:", path)
		}
	}, func(path string, isDir bool) {
		// Callback for removed files and directories
		if isDir {
			fmt.Println("removed dir:", path)
		} else {
			fmt.Println("removed file:", path)
		}
	}, func(path string, isDir bool, failed func()) {
		// Callback for modified files and directories
		if isDir {
			fmt.Println("modified dir:", path)
		} else {
			fmt.Println("modified file:", path)
		}
	})
	defer f.Close()

	// Watch the current directory
	err := f.Watch(".")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	// Keep the application running to receive file events
	select {}
}

API Documentation

  • NewFileWatcher: Create a new instance of the FileWatcher.
  • Close: Close the FileWatcher and stop watching.
  • Watch: Start watching a specified file or directory.
  • Unwatch: Stop watching a specified file or directory.

License

GNU AGPLv3 Image

This program is Free Software: You can use, study share and improve it at your will. Specifically you can redistribute and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileWatcher

type FileWatcher struct {
	// contains filtered or unexported fields
}

func NewFileWatcher

func NewFileWatcher(updateInterval time.Duration, created func(path string, isDir bool, failed func()), removed func(path string, isDir bool), modified func(path string, isDir bool, failed func())) *FileWatcher

func (*FileWatcher) Close

func (f *FileWatcher) Close()

func (*FileWatcher) Unwatch

func (f *FileWatcher) Unwatch(path string) error

func (*FileWatcher) Watch

func (f *FileWatcher) Watch(path string) error

Jump to

Keyboard shortcuts

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