notification

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package notifications fixes the problem of multiple file change notifications for the same file from the OS API. With FileNotificationWaiter(chanA, chanB, data) you can send data to the chanB if nothing was send to the chanA for 5 seconds

The flow: - For each file create a channel and store it with RegisterFileNotification() - Call FileNotificationWaiter() as a go routin with the created channel and other needed data - On the next file change notification check if the channel for this file exists, if so send true to the channel - If nothing was send on the channel, FileNotificationWaiter() will send the data to the provided channel after 5 seconds

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType int

ActionType represents what happens with the file

const (
	// Invalid action is 0
	Invalid ActionType = iota
	// FileAdded - the file was added to the directory.
	FileAdded // 1
	// FileRemoved - the file was removed from the directory.
	FileRemoved // 2
	// FileModified - the file was modified. This can be a change in the time stamp or attributes.
	FileModified // 3
	// FileRenamedOldName - the file was renamed and this is the old name.
	FileRenamedOldName // 4
	// FileRenamedNewName - the file was renamed and this is the new name.
	FileRenamedNewName // 5
)

type Error

type Error struct {
	Stack   string
	Message string
	Level   string
}

Error ...

func FormatError added in v1.1.0

func FormatError(level, msg string) Error

type Event

type Event struct {
	Action             ActionType
	MimeType           string
	Machine            string
	FileName           string
	AbsolutePath       string
	RelativePath       string
	DirectoryPath      string
	WatchDirectoryName string
	Size               int64
	Timestamp          time.Time
	UUID               uuid.UUID
	Checksum           string
}

Event ...

type Level added in v1.1.0

type Level uint32
const (
	// UNSPECIFIED error level = 0
	UNSPECIFIED Level = iota
	TRACE
	DEBUG
	INFO
	WARNING
	ERROR
	CRITICAL
)

func (Level) String added in v1.1.0

func (level Level) String() string

String implements Stringer.

type Waiter

type Waiter struct {
	EventCh  chan Event
	ErrorCh  chan Error
	Timeout  time.Duration
	MaxCount int
}

Waiter ...

func (*Waiter) LookupForFileNotification

func (w *Waiter) LookupForFileNotification(path string) (chan bool, bool)

LookupForFileNotification returns a channel for a given file path

func (*Waiter) RegisterFileNotification

func (w *Waiter) RegisterFileNotification(path string)

RegisterFileNotification channel for a given file path, use this channel for with FileNotificationWaiter() function

func (*Waiter) UnregisterFileNotification

func (w *Waiter) UnregisterFileNotification(path string)

UnregisterFileNotification channel for a given file path

func (*Waiter) Wait

func (w *Waiter) Wait(fileData *Event)

Wait will send fileData to the chan stored in CallbackData after 5 seconds if no signal is received on waitChan. TODO: this can be done better with a general type of channel and any data

Jump to

Keyboard shortcuts

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