command

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotReceiver    = errors.New("not implement receiver interface")
	ErrNotCommand     = errors.New("not implement Command interface")
	ErrNotUndoCommand = errors.New("not implement UndoCommand interface")
	ErrNotRedoCommand = errors.New("not implement RedoCommand interface")
)
View Source
var (
	ErrNotFoundUndoCommand = errors.New("not found command in undo command stack")
	ErrNotFoundRedoCommand = errors.New("not found command in redo command stack")
)

Functions

This section is empty.

Types

type Command

type Command interface {
	// Execute a unit of processing work to be performed
	Execute(ctx context.Context) (context.Context, error)
}

A Command encapsulates a unit of processing work to be performed.

func Chain

func Chain(cmd Command, middlewares ...Middleware) Command

Chain decorates the given Command with all middlewares.

type CommandFunc

type CommandFunc func(ctx context.Context) (context.Context, error)

The CommandFunc type is an adapter to allow the use of ordinary functions as Command. If f is a function with the appropriate signature, CommandFunc(f) is a Command that calls f.

func (CommandFunc) Execute

func (f CommandFunc) Execute(ctx context.Context) (context.Context, error)

Execute calls f(ctx).

type ConcreteCommand

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

func NewConcreteCommand

func NewConcreteCommand(receiver Receiver) *ConcreteCommand

func (*ConcreteCommand) Execute

func (cmd *ConcreteCommand) Execute(ctx context.Context) error

type Invoker

type Invoker struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Invoker) Call

func (invoker *Invoker) Call(ctx context.Context, cmd Command) (context.Context, error)

func (*Invoker) Redo

func (invoker *Invoker) Redo(ctx context.Context) (context.Context, error)

func (*Invoker) Undo

func (invoker *Invoker) Undo(ctx context.Context) (context.Context, error)

type Middleware

type Middleware interface {
	// Decorate wraps the underlying Command, adding some functionality.
	Decorate(cmd Command) Command
}

Middleware allows us to write something like decorators to Command. It can execute something before Execute or after.

type MiddlewareFunc

type MiddlewareFunc func(cmd Command) Command

The MiddlewareFunc type is an adapter to allow the use of ordinary functions as Middleware. If f is a function with the appropriate signature, MiddlewareFunc(f) is a Middleware that calls f.

func (MiddlewareFunc) Decorate

func (f MiddlewareFunc) Decorate(cmd Command) Command

Decorate call f(cmd).

type Receiver

type Receiver interface {
	Action(ctx context.Context) error
}

type RedoCommand

type RedoCommand interface {
	Redo(ctx context.Context) (context.Context, error)
}

RedoCommand redo a Command

type RedoCommandFunc

type RedoCommandFunc func(ctx context.Context) (context.Context, error)

The RedoCommandFunc type is an adapter to allow the use of ordinary functions as RedoCommand. If f is a function with the appropriate signature, RedoCommandFunc(f) is a RedoCommand that calls f.

func (RedoCommandFunc) Redo

Redo calls f(ctx).

type RichCommand

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

func NewRichCommand

func NewRichCommand(cmd Command, undoCmd UndoCommand, redoCmd RedoCommand) *RichCommand

func (*RichCommand) Execute

func (cmd *RichCommand) Execute(ctx context.Context) (context.Context, error)

func (*RichCommand) Redo

func (cmd *RichCommand) Redo(ctx context.Context) (context.Context, error)

func (*RichCommand) Undo

func (cmd *RichCommand) Undo(ctx context.Context) (context.Context, error)

type UndoCommand

type UndoCommand interface {
	Undo(ctx context.Context) (context.Context, error)
}

UndoCommand undo a Command

type UndoCommandFunc

type UndoCommandFunc func(ctx context.Context) (context.Context, error)

The UndoCommandFunc type is an adapter to allow the use of ordinary functions as UndoCommand. If f is a function with the appropriate signature, UndoCommandFunc(f) is a UndoCommand that calls f.

func (UndoCommandFunc) Undo

Undo calls f(ctx).

Jump to

Keyboard shortcuts

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