core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileSystemTimeFormat = "2006-01-02_15-04-05"
	PackageName          = "agenor"
)

Variables

View Source
var (
	Now        TimeFunc
	Perms      Permissions
	ResumeTail string
)
View Source
var BenignNodeFilterDef = FilterDef{
	Type:        enums.FilterTypeRegex,
	Description: "benign allow all",
	Pattern:     ".",
	Scope:       enums.ScopeTree,
}
View Source
var ErrDetectedSpawnStackOverflow = errors.New(
	"spawn resume stack-overflow protection",
)
View Source
var ErrGuardianCantDecorateItemSealed = errors.New(
	"can't decorate, last item is sealed",
)

ErrGuardianCantDecorateItemSealedError creates an untranslated error to indicate last item is sealed

View Source
var ErrNilForest = errors.New(
	"forest is nil",
)
View Source
var ErrWrongPrimaryFacade = errors.New(
	"wrong primary facade",
)
View Source
var ErrWrongResumeFacade = errors.New(
	"wrong resume facade",
)

Functions

func IsBrokerTopicNotFoundError

func IsBrokerTopicNotFoundError(err error) bool

IsBrokerTopicNotFoundError uses errors.Is to check if the err's error tree contains the core error: BrokerTopicNotFoundError

func IsInvalidNotificationMuteRequestedError

func IsInvalidNotificationMuteRequestedError(err error) bool

IsInvalidNotificationMuteRequestedError uses errors.Is to check if the err's error tree contains the core error: InvalidNotificationMuteRequestedError

func IsInvalidPeriscopeRootPathError

func IsInvalidPeriscopeRootPathError(err error) bool

IsInvalidPeriscopeRootPathError uses errors.Is to check if the err's error tree contains the core error: InvalidPeriscopeRootPathError

func IsInvalidResumeStateTransitionError

func IsInvalidResumeStateTransitionError(err error) bool

IsInvalidResumeStateTransitionError uses errors.Is to check if the err's error tree contains the core error: InvalidResumeStateTransitionNativeError

func IsMissingHibernationDetacherFunctionError

func IsMissingHibernationDetacherFunctionError(err error) bool

IsMissingHibernationDetacherFunctionError uses errors.Is to check if the err's error tree contains the core error: MissingListenDetacherFunctionError

func IsNewItemAlreadyExtendedError

func IsNewItemAlreadyExtendedError(err error) bool

IsNewItemAlreadyExtendedError uses errors.Is to check if the err's error tree contains the core error: NewItemAlreadyExtendedError

func IsResumeControllerNotSetError

func IsResumeControllerNotSetError(err error) bool

IsResumeControllerNotSetError uses errors.Is to check if the err's error tree contains the core error: ResumeControllerNotSetError

func NewBrokerTopicNotFoundError

func NewBrokerTopicNotFoundError(topic string) error

NewBrokerTopicNotFoundError creates an untranslated error to indicate the topic requested was not found; ie it wasn't registered.

func NewInvalidNotificationMuteRequestedError

func NewInvalidNotificationMuteRequestedError(notification string) error

NewInvalidNotificationMuteRequestedError creates an untranslated error to indicate invalid notification mute requested (internal error)

func NewInvalidPeriscopeRootPathError

func NewInvalidPeriscopeRootPathError(tree, current string) error

NewInvalidPeriscopeRootPathError creates an untranslated error to indicate invalid periscope tree path, ie the current path is not a child directory relative to the tree path.

func NewInvalidResumeStateTransitionError

func NewInvalidResumeStateTransitionError(state string) error

NewInvalidResumeStateTransitionError creates an untranslated error to indicate in invalid resume state transition

func NewItemAlreadyExtendedError

func NewItemAlreadyExtendedError(path string) error

NewItemAlreadyExtendedError creates an untranslated error to indicate the node has already been extended

func NewMissingHibernationDetacherFunctionError

func NewMissingHibernationDetacherFunctionError(state string) error

NewMissingHibernationDetacherFunctionError creates an untranslated error to indicate hibernation detacher function nt defined

func NewResumeControllerNotSetError

func NewResumeControllerNotSetError(from string) error

NewResumeControllerNotSetError creates an untranslated error to indicate resume controller not set

Types

type ActiveState

type ActiveState struct {
	Tree                string
	TraverseDescription FsDescription
	ResumeDescription   FsDescription
	Subscription        enums.Subscription
	Hibernation         enums.Hibernation
	CurrentPath         string
	IsDir               bool
	Depth               int
	Metrics             Metrics
}

func (*ActiveState) Clone

func (s *ActiveState) Clone() *ActiveState

type BeginHandler

type BeginHandler func(tree string)

BeginHandler invoked before traversal begins

type ChainQueryStatusHook

type ChainQueryStatusHook func(result fs.FileInfo, err error,
	qsys fs.StatFS, path string,
) (fs.FileInfo, error)

ChainQueryStatusHook chainable version of QueryStatusHook

type ChainReadDirectoryHook

type ChainReadDirectoryHook func(result []fs.DirEntry, err error,
	rsys fs.ReadDirFS, dirname string,
) ([]fs.DirEntry, error)

ChainReadDirectoryHook chainable version of

type ChainSortHook

type ChainSortHook func(
	entries []fs.DirEntry, custom ...any,
)

ChainSortHook chainable version of SortHook

type ChainSubPathHook

type ChainSubPathHook func(result string,
	info *SubPathInfo,
) string

ChainSubPathHook chainable version of SubPathHook

type ChildFilterDef

type ChildFilterDef struct {
	// Type specifies the type of filter (mandatory)
	Type enums.FilterType

	// Description describes filter (optional)
	Description string

	// Pattern filter definition (mandatory)
	Pattern string

	// Negate, reverses the applicability of the filter (Defaults to false)
	Negate bool
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type ChildTraverseFilter

type ChildTraverseFilter interface {
	// Description describes filter
	Description() string

	// Validate ensures the filter definition is valid, returns
	// error when invalid
	Validate() error

	// Source, filter definition (comes from filter definition Pattern)
	Source() string

	// Matching returns the collection of files contained within this
	// item's directory that matches this filter.
	Matching(children []fs.DirEntry) []fs.DirEntry
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type Client

type Client func(servant Servant) error

Client is the callback invoked for each file system node found during traversal.

type Completion

type Completion func() bool

Completion

func (Completion) IsComplete

func (fn Completion) IsComplete() bool

type Crate

type Crate struct {
	Metrics Metrics
}

type DirectoryContents

type DirectoryContents interface {
	All() []fs.DirEntry
	Directories() []fs.DirEntry
	Files() []fs.DirEntry
}

DirectoryContents represents the contents of a directory's contents and handles sorting order which by default is different between various operating systems. This abstraction removes the differences in sorting behaviour on different platforms.

type EndHandler

type EndHandler func(result TraverseResult)

EndHandler invoked at the end of traversal

type Extension

type Extension struct {
	Depth   int               // traversal depth relative to the tree
	IsLeaf  bool              // defines whether this node a leaf node
	Name    string            // derived as the leaf segment from filepath.Split
	Parent  string            // derived as the directory from filepath.Split
	SubPath string            // represents the path between the tree and the current item
	Scope   enums.FilterScope // type of directory corresponding to the Filter Scope
	Custom  any               // to be set and used by the client
}

Extension provides extended information if the client requests it by setting the DoExtend boolean in the traverse options.

type FilterDef

type FilterDef struct {
	// Type specifies the type of filter (mandatory)
	Type enums.FilterType

	// Description describes filter (optional)
	Description string

	// Pattern filter definition (mandatory)
	Pattern string

	// Scope which file system entries this filter applies to (defaults
	// to ScopeAllEn)
	Scope enums.FilterScope

	// Negate, reverses the applicability of the filter (Defaults to false)
	Negate bool

	// IfNotApplicable, when the filter does not apply to a directory entry,
	// this value determines whether the callback is invoked for this entry
	// or not (defaults to true).
	IfNotApplicable enums.TriStateBool

	// Poly allows for the definition of a PolyFilter which contains separate
	// filters that target files and directories separately. If present, then
	// all other fields are redundant, since the filter definitions inside
	// Poly should be referred to instead.
	Poly *PolyFilterDef
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type Forest

type Forest struct {
	// T is the file system that contains just the functionality required
	// for traversal. It can also represent other file systems including afero,
	// providing the appropriate adapters are in place.
	T tfs.TraversalFS

	// R is the file system required for resume operations, ie we load
	// and save resume state via this file system instance, which is
	// distinct from the traversal file system.
	R tfs.TraversalFS
}

Forest contains the logical file systems required for navigation.

type FsDescription

type FsDescription struct {
	IsRelative bool
}

FsDescription description of a file system

type HibernateHandler

type HibernateHandler func(description string)

HibernateHandler is a generic handler that is used by hibernation to indicate wake or sleep.

type HibernateOptions

type HibernateOptions struct {
	// WakeAt defines a filter for hibernation wake condition
	WakeAt *FilterDef

	// SleepAt defines a filter for hibernation sleep condition
	SleepAt *FilterDef

	// Behaviour contains hibernation behavioural aspects
	Behaviour HibernationBehaviour
}

HibernateOptions

func (*HibernateOptions) IsHibernateActive

func (o *HibernateOptions) IsHibernateActive() bool

type HibernationBehaviour

type HibernationBehaviour struct {
	// InclusiveWake when wake occurs, permit client callback to
	// be invoked for the current node. Inclusive, true by default
	InclusiveWake bool

	// InclusiveSleep when sleep occurs, permit client callback to
	// be invoked for the current node. Exclusive, false by default.
	InclusiveSleep bool
}

HibernationBehaviour

type Metric

type Metric interface {
	Type() enums.Metric
	Value() MetricValue
}

Metric represents query access to the metric. The client registering the metric should maintain it's mutate access to the metric so they can update it.

type MetricValue

type MetricValue = uint

type Metrics

type Metrics map[enums.Metric]*NavigationMetric

type MutableMetric

type MutableMetric interface {
	Metric
	Tick() MetricValue
	Times(increment uint) MetricValue
}

MutableMetric represents write access to the metric

type NavigationMetric struct {
	T       enums.Metric
	Counter MetricValue
}
func (m *NavigationMetric) Tick() MetricValue
func (m *NavigationMetric) Times(increment uint) MetricValue
func (m *NavigationMetric) Type() enums.Metric
func (m *NavigationMetric) Value() MetricValue
type Navigator interface {
	Navigate(ctx context.Context) (TraverseResult, error)
}

type Node

type Node struct {
	Path      string
	Entry     fs.DirEntry // contains a FileInfo via Info() function
	Info      fs.FileInfo // optional file info instance
	Extension Extension   // extended information about the directory entry
	Error     error
	Children  []fs.DirEntry
	Parent    *Node
	// contains filtered or unexported fields
}

Node represents a file system node event and represents each file system entity encountered during traversal. The event representing the tree node does not have a DirEntry because it is not created as a result of a readDir invoke. Therefore, the client has to know that when its function is called back, there will be no DirEntry for the tree node.

func New

func New(
	path string, entry fs.DirEntry, info fs.FileInfo, parent *Node, err error,
) *Node

New creates a new Node

func Top

func Top(tree string, info fs.FileInfo) *Node

Top creates a new Node which represents the root of the directory tree to traverse.

func (*Node) IsDirectory

func (n *Node) IsDirectory() bool

IsDirectory indicates wether this node is a directory.

type Permissions

type Permissions struct {
	File fs.FileMode
	Dir  fs.FileMode
}

type PolyFilterDef

type PolyFilterDef struct {
	File      FilterDef
	Directory FilterDef
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type QueryStatusHook

type QueryStatusHook func(qsys fs.StatFS, path string) (fs.FileInfo, error)

QueryStatusHook function signature that enables the default to be overridden. (By default, uses Lstat)

type ReadDirectoryHook

type ReadDirectoryHook func(rsys fs.ReadDirFS, dirname string) ([]fs.DirEntry, error)

ReadDirectoryHook hook function to define implementation of how a directory's entries are read. A default implementation is preset, so does not have to be set by the client.

type Reporter

type Reporter interface {
	Count(enums.Metric) MetricValue
}

Reporter represents query access to the metrics Supervisor

type ResultCompletion

type ResultCompletion interface {
	IsComplete() bool
}

ResultCompletion used to determine if the result really represents final navigation completion.

type SampleFilterDef

type SampleFilterDef struct {
	// Type specifies the type of filter (mandatory)
	Type enums.FilterType

	// Description describes filter (optional)
	Description string

	// Pattern filter definition (mandatory except if using Custom)
	Pattern string

	// Scope which file system entries this filter applies to;
	// for sampling, only ScopeFile and ScopeDirectory are valid.
	Scope enums.FilterScope

	// Negate, reverses the applicability of the filter (Defaults to false)
	Negate bool

	// Poly allows for the definition of a PolyFilter which contains separate
	// filters that target files and directories separately. If present, then
	// all other fields are redundant, since the filter definitions inside
	// Poly should be referred to instead.
	Poly *PolyFilterDef

	// Custom client defined sampling filter
	//
	Custom SampleTraverseFilter
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type SampleTraverseFilter

type SampleTraverseFilter interface {
	// Description describes filter
	Description() string

	// Validate ensures the filter definition is valid, panics when invalid
	Validate() error

	// Matching returns the collection of files contained within this
	// item's directory that matches this filter.
	Matching(children []fs.DirEntry) []fs.DirEntry
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type Servant

type Servant interface {
	Node() *Node
}

Servant provides the client with facility to request properties about the current navigation node.

type Session

type Session interface {
	ResultCompletion
	StartedAt() time.Time
	Elapsed() time.Duration
}

Session represents a traversal session and keeps tracks of timing.

type SimpleHandler

type SimpleHandler func()

SimpleHandler is a function that takes no parameters and can be used by any notification with this signature.

type SortHook

type SortHook func(entries []fs.DirEntry, custom ...any)

SortHook hook function to define how directory entries are sorted. Does not have to be set explicitly. This will be set according to the IsCaseSensitive on the TraverseOptions, but can be overridden if needed.

type SubPathHook

type SubPathHook func(info *SubPathInfo) string

SubPathHook

type SubPathInfo

type SubPathInfo struct {
	Tree            string
	Node            *Node
	KeepTrailingSep bool
}

type Supervisor

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

func NewSupervisor

func NewSupervisor() *Supervisor

func (*Supervisor) Count

func (s *Supervisor) Count(mt enums.Metric) MetricValue

func (*Supervisor) Many

func (s *Supervisor) Many(metrics ...enums.Metric) Metrics

func (*Supervisor) Single

func (s *Supervisor) Single(mt enums.Metric) *NavigationMetric

type TimeFunc

type TimeFunc func() time.Time

TimeFunc get time

type TraverseFilter

type TraverseFilter interface {
	// Description describes filter
	Description() string

	// Validate ensures the filter definition is valid, returns
	// error when invalid
	Validate() error

	// Source, filter definition (comes from filter definition Pattern)
	Source() string

	// IsMatch does this node match the filter
	IsMatch(node *Node) bool

	// IsApplicable is this filter applicable to this node's scope
	IsApplicable(node *Node) bool

	// Scope, what items this filter applies to
	Scope() enums.FilterScope
}

TraverseFilter filter that can be applied to file system entries. When specified, the callback will only be invoked for file system nodes that pass the filter.

type TraverseResult

type TraverseResult interface {
	Metrics() Reporter
	Session() Session
}

TraverseResult

Jump to

Keyboard shortcuts

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