hooks

package module
v0.0.0-...-3190f46 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

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
	Create(v json.RawMessage) error
	Serialize() json.RawMessage

	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"`
	CreatedAt *time.Time `json:"createdAt"`

	RunOn     RunOn  `json:"runOn"`
	Recursive bool   `json:"recursive"`
	Action    Action `json:"action"`
}

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) MarshalJSON

func (h *Hook) MarshalJSON() ([]byte, error)

func (*Hook) UnmarshalJSON

func (h *Hook) UnmarshalJSON(data []byte) error

type Hooks

type Hooks []*Hook

Hooks is the definition of the pointer array of Hook struct

type Loader

type Loader interface {
	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
)

Jump to

Keyboard shortcuts

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