- Hands-On System Programming with Go
- Alex Guerrieri
- 131字
- 2021-06-24 13:42:29
Filesystem events
Go has some experimental features in the golang.org/x/ package that are located under Go's GitHub handler (https://github.com/golang/). The golang.org/x/sys package is part of this list and includes a subpackage dedicated to Unix system events. This has been used to build a feature that is missing from Go's file functionality and can be really useful – observing a certain path for events on files like creation, deletion, and update.
The two most famous implementations are as follows:
- notify: github.com/rjeczalik/notify
- fsnotify: github.com/fsnotify/fsnotify
Both packages expose a function that allows the creation of watchers. Watchers are structures that contain channels that are in charge of delivering file events. They also expose another function that 's responsible for terminating/closing the watchers and underlying channels.