Documentation ¶
Overview ¶
Package gorsn implements utility routines for periodically monitoring a folder and its sub-folders content to detect any change such as file or folder deletion and creation along with content or permissions modification. Then it emits an appropriate event object on a consumable channel. The notifier system it provides could be stopped and status checked once started. It finally accepts a set of options which are safe to be modified by multiple goroutines even during its operations.
Index ¶
- Constants
- type ErrorCode
- type Event
- type Options
- func (o *Options) SetIgnoreCreateEvent(v bool) *Options
- func (o *Options) SetIgnoreDeleteEvent(v bool) *Options
- func (o *Options) SetIgnoreErrors(v bool) *Options
- func (o *Options) SetIgnoreFileEvent(v bool) *Options
- func (o *Options) SetIgnoreFolderContentEvent(v bool) *Options
- func (o *Options) SetIgnoreFolderEvent(v bool) *Options
- func (o *Options) SetIgnoreModifyEvent(v bool) *Options
- func (o *Options) SetIgnoreNoChangeEvent(v bool) *Options
- func (o *Options) SetIgnorePermEvent(v bool) *Options
- func (o *Options) SetIgnoreSymlink(v bool) *Options
- func (o *Options) SetMaxWorkers(v int) *Options
- func (o *Options) SetQueueSize(v int) *Options
- func (o *Options) SetScanInterval(v time.Duration) *Options
- type ScanNotifier
Constants ¶
const ( CREATE eventName = "CREATE" MODIFY eventName = "MODIFY" DELETE eventName = "DELETE" PERM eventName = "PERM" ERROR eventName = "ERROR" NOCHANGE eventName = "NOCHANGE" )
const ( FILE pathType = "FILE" DIR pathType = "DIRECTORY" SYMLINK pathType = "SYMLINK" UNSUPPORTED pathType = "UNSUPPORTED" )
const ( DEFAULT_QUEUE_SIZE = 10 DEFAULT_MAX_WORKERS = 1 DEFAULT_SCAN_INTERVAL = 1 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode describes a failure on the resource scan notifier.
const ( // Unexpected error ErrInternalError ErrorCode = "internal error" // Operations errors ErrInvalidRootDirPath ErrorCode = "invalid root directory path" ErrInitialization ErrorCode = "error parsing root directory" ErrScanIsNotRunning ErrorCode = "scan notifier is not running" ErrScanAlreadyStarted ErrorCode = "scan notifier has already started" ErrScanIsStopping ErrorCode = "scan notifier is stopping" ErrScanIsNotReady ErrorCode = "scan notifier is not (re)initialized" ErrScanIsNotPaused ErrorCode = "scan notifier is not paused" )
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func (*Options) SetIgnoreCreateEvent ¶
func (*Options) SetIgnoreDeleteEvent ¶
func (*Options) SetIgnoreErrors ¶
func (*Options) SetIgnoreFileEvent ¶
func (*Options) SetIgnoreFolderContentEvent ¶
func (*Options) SetIgnoreFolderEvent ¶
func (*Options) SetIgnoreModifyEvent ¶
func (*Options) SetIgnoreNoChangeEvent ¶
func (*Options) SetIgnorePermEvent ¶
func (*Options) SetIgnoreSymlink ¶
func (*Options) SetMaxWorkers ¶
func (*Options) SetQueueSize ¶
type ScanNotifier ¶
type ScanNotifier interface { // Queue returns the channel to listen on for receiving changes events. // The returned channel is read-only to avoid closing or writing on. Queue() <-chan Event // Start begins periodic scanning of root directory and emitting events. Start(context.Context) error // Stop aborts the scanning of root directory and sending events. Stop() error // IsRunning reports whether the scan notifier has started. IsRunning() bool // Flush clears internal cache history of files and directories under monitoring. // Once succeeded, `CREATE` is the next event for each item under monitoring. // This could be used directly after initialization of the scan notifier instance // in order to receive the list of item (via `CREATE` event) inside root directory. // Calling this while the scan notifier has started will make the scanner to detect // each item like newly created into the root directory so the notifier will emit // `CREATE` event for those items almost immediately. Flush() // Pause instructs the scanner to escape at each polling interval so no changes // detection will happen then no new events will be sent. // Use Resume() to restart the normal scanning and event notification processes. Pause() error // Resume restarts the scanner and notifier after being into `paused` state. Resume() error }
ScanNotifier is an interface which defines a set of available actions.
func New ¶
func New(root string, opts *Options) (ScanNotifier, error)
New provides an initialized object which satisfies the ScanNotifier interface. It initializes itself based on the `root` value which is expected to be a path to an accessible directory. The content of the root directory will be parsed and loaded based on the options provided by `opts`. It returns and error which wraps `ErrInvalidRootDirPath` in case the root path is not an accessible directory. `ErrInitialization` means the initialization encoutered an error.