hooks

package
v0.0.0-...-96b211d Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: GPL-3.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Provider() string
	Version() string
	Sample() interface{}

	New() Action
	Setup(v SetupMap) error

	Execute(aI *ActionInfo) error
}

Action is the interface for the hook operation execution

type ActionInfo

type ActionInfo struct {
	Time        time.Time `json:"time"`
	Action      string    `json:"action"`               // created, copied, moved, deleted
	SourcePath  string    `json:"sourcePath"`           // full path of the source file/folder that took action
	TargetPath  *string   `json:"targetPath,omitempty"` // full path of the target file/folder that took action (only copy, move)
	Folder      bool      `json:"folder"`               // path is a folder or not
	Overwritten bool      `json:"overwritten"`          // path is a file and it was overwritten
}

ActionInfo struct holds the action details that should be used by the Action provider

func NewActionInfoForCopiedFile

func NewActionInfoForCopiedFile(sourcePath string, targetPath string, overwritten bool) *ActionInfo

func NewActionInfoForCopiedFolder

func NewActionInfoForCopiedFolder(sourcePath string, targetPath string) *ActionInfo

func NewActionInfoForCreated

func NewActionInfoForCreated(createdPath string, folder bool) *ActionInfo

func NewActionInfoForDeleted

func NewActionInfoForDeleted(deletedPath string, folder bool) *ActionInfo

func NewActionInfoForMovedFile

func NewActionInfoForMovedFile(sourcePath string, targetPath string, overwritten bool) *ActionInfo

func NewActionInfoForMovedFolder

func NewActionInfoForMovedFolder(sourcePath string, targetPath string) *ActionInfo

type Hook

type Hook struct {
	Id        *string    `json:"id"`
	Created   *time.Time `json:"created"`
	RunOn     RunOn      `json:"runOn" bson:"runOn"`
	Recursive bool       `json:"recursive"`
	Provider  string     `json:"provider"`
	Setup     SetupMap   `json:"setup"`
	// contains filtered or unexported fields
}

Hook struct holds the information of the action for the Folder base on RunOn setup RunOn is the type of the action that can be reason for the execution Times is the counter for the allowed executions. -1 is no limit. 0 is execution is not allowed anymore Recursive checks if the hook responsible for the sub folders Action is the action to take

func (*Hook) Action

func (h *Hook) Action() (Action, error)

func (*Hook) Prepare

func (h *Hook) Prepare()

type Hooks

type Hooks []*Hook

Hooks is the definition of the pointer array of Hook struct

type Loader

type Loader interface {
	HooksPath() string

	List() []Action
	Get(name string) Action
}
var CurrentLoader Loader

func NewLoader

func NewLoader(hooksPath string, logger *zap.Logger) Loader

type RunOn

type RunOn int
const (
	All     RunOn = 1 // is executed in anyway
	Created RunOn = 2 // Folder/File or SubFolder/SubFile (if recursive) is newly Created
	Updated RunOn = 3 // Folder/File or SubFolder/File is Copied or Moved (Renamed)
	Deleted RunOn = 4 // Folder/File or SubFolder/SubFile (if recursive) is completely Deleted
)

type SetupMap

type SetupMap map[string]interface{}

SetupMap is the simplified type name for underlying map

Jump to

Keyboard shortcuts

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