Introduction

gfsnotify can watch changes in specified files/directories, such as additions, deletions, modifications, and renaming of files.

Usage:

  1. import "github.com/gogf/gf/v2/os/gfsnotify"

API Documentation:

https://pkg.go.dev/github.com/gogf/gf/v2/os/gfsnotify

It is recommended to use the Add and Remove module methods provided by the gfsnotify module for adding and canceling watching. The reasons for this recommendation are explained in the following sections.

Additionally, you can also create a watching management object using the New method and then perform watching management. When adding watching, you need to provide a callback function that triggers during watching, with the parameter type being a *gfsnotify.Event object pointer.

Documentation

📄️ File Watching - AddDefine and implement file watching functionality, using the gfsnotify library in the GoFrame framework to watch file creation, writing, deletion, renaming, and permission modification events in a specified directory. Supports recursive watching, automatically detecting changes in files within directories and subdirectories, with flexible watching options and real-time output of file event information related to the directory.

📄️ File Watching - RemoveThis document details how to use the Remove method and the RemoveCallback method in the GoFrame framework to remove watching callback functions for files and directories. It uses example code to illustrate how to add and remove watching callbacks, thereby improving system resource efficiency and ensuring the flexibility and controllability of file operation watching.

📄️ File Watching - System VarsIn the Linux system, the gfsnotify module implements file and directory watching through the inotify feature, limited by system kernel parameters such as fs.inotify.max_user_instances and fs.inotify.max_user_watches. These parameters can be viewed and modified via command line to suit different watching needs.