notify

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: EUPL-1.2 Imports: 19 Imported by: 0

Documentation

Overview

Package notify provides some notification services to be used by box services.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDirectory = errors.New("unable to retrieve zettel directory information")

ErrNoDirectory signals missing directory data.

Functions

This section is empty.

Types

type DirEntry

type DirEntry struct {
	Zid          id.Zid
	MetaName     string   // file name of meta information
	ContentName  string   // file name of zettel content
	ContentExt   string   // (normalized) file extension of zettel content
	UselessFiles []string // list of other content files
}

DirEntry stores everything for a directory entry.

func (*DirEntry) HasMetaInContent

func (e *DirEntry) HasMetaInContent() bool

HasMetaInContent returns true, if metadata will be stored in the content file.

func (*DirEntry) IsValid

func (e *DirEntry) IsValid() bool

IsValid checks whether the entry is valid.

func (*DirEntry) SetupFromMetaContent

func (e *DirEntry) SetupFromMetaContent(m *meta.Meta, content zettel.Content, getZettelFileSyntax func() []string)

SetupFromMetaContent fills entry data based on metadata and zettel content.

type DirService

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

DirService specifies a directory service for file based zettel.

func NewDirService

func NewDirService(box box.ManagedBox, log *logger.Logger, notifier Notifier, chci chan<- box.UpdateInfo) *DirService

NewDirService creates a new directory service.

func (*DirService) DeleteDirEntry

func (ds *DirService) DeleteDirEntry(zid id.Zid) error

DeleteDirEntry removes a entry from the directory.

func (*DirService) GetDirEntries

func (ds *DirService) GetDirEntries(constraint query.RetrievePredicate) []*DirEntry

GetDirEntries returns a list of directory entries, which satisfy the given constraint.

func (*DirService) GetDirEntry

func (ds *DirService) GetDirEntry(zid id.Zid) *DirEntry

GetDirEntry returns a directory entry with the given zid, or nil if not found.

func (*DirService) NumDirEntries

func (ds *DirService) NumDirEntries() int

NumDirEntries returns the number of entries in the directory.

func (*DirService) Refresh

func (ds *DirService) Refresh()

Refresh the directory entries.

func (*DirService) RenameDirEntry

func (ds *DirService) RenameDirEntry(oldEntry *DirEntry, newZid id.Zid) (DirEntry, error)

RenameDirEntry replaces an existing directory entry with a new one.

func (*DirService) SetNewDirEntry

func (ds *DirService) SetNewDirEntry() (id.Zid, error)

SetNewDirEntry calculates an empty directory entry with an unused identifier and stores it in the directory.

func (*DirService) Start

func (ds *DirService) Start()

Start the directory service.

func (*DirService) State added in v0.11.0

func (ds *DirService) State() DirServiceState

State the current service state.

func (*DirService) Stop

func (ds *DirService) Stop()

Stop the directory service.

func (*DirService) UpdateDirEntry

func (ds *DirService) UpdateDirEntry(updatedEntry *DirEntry) error

UpdateDirEntry updates an directory entry in place.

type DirServiceState added in v0.11.0

type DirServiceState uint8

DirServiceState signal the internal state of the service.

The following state transitions are possible: --newDirService--> dsCreated dsCreated --Start--> dsStarting dsStarting --last list notification--> dsWorking dsWorking --directory missing--> dsMissing dsMissing --last list notification--> dsWorking --Stop--> dsStopping

const (
	DsCreated  DirServiceState = iota
	DsStarting                 // Reading inital scan
	DsWorking                  // Initial scan complete, fully operational
	DsMissing                  // Directory is missing
	DsStopping                 // Service is shut down
)

type EntryFetcher

type EntryFetcher interface {
	Fetch() ([]string, error)
}

EntryFetcher return a list of (file) names of an directory.

type Event

type Event struct {
	Op   EventOp
	Name string
	Err  error // Valid iff Op == Error
}

Event represents a single container / element event.

type EventOp

type EventOp uint8

EventOp describe a notification operation.

const (
	Error   EventOp // Error while operating
	Make            // Make container
	List            // List container
	Destroy         // Destroy container
	Update          // Update element
	Delete          // Delete element
)

Valid constants for event operations.

Error signals a detected error. Details are in Event.Err.

Make signals that the container is detected. List events will follow.

List signals a found file, if Event.Name is not empty. Otherwise it signals the end of files within the container.

Destroy signals that the container is not there any more. It might me Make later again.

Update signals that file Event.Name was created/updated. File name is relative to the container.

Delete signals that file Event.Name was removed. File name is relative to the container's name.

func (EventOp) String

func (c EventOp) String() string

String representation of operation code.

type Notifier

type Notifier interface {
	// Return the channel
	Events() <-chan Event

	// Signal a refresh of the container. This will result in some events.
	Refresh()

	// Close the notifier (and eventually the channel)
	Close()
}

Notifier send events about their container and content.

func NewFSDirNotifier

func NewFSDirNotifier(log *logger.Logger, path string) (Notifier, error)

NewFSDirNotifier creates a directory based notifier that receives notifications from the file system.

func NewSimpleDirNotifier

func NewSimpleDirNotifier(log *logger.Logger, path string) (Notifier, error)

NewSimpleDirNotifier creates a directory based notifier that will not receive any notifications from the operating system.

func NewSimpleZipNotifier

func NewSimpleZipNotifier(log *logger.Logger, zipPath string) Notifier

NewSimpleZipNotifier creates a zip-file based notifier that will not receive any notifications from the operating system.

Jump to

Keyboard shortcuts

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