keydriven

package
v0.0.0-...-9f34108 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyAlreadyDefined the given key is already defined in the executor
	ErrKeyAlreadyDefined = errors.New("Key is already defined")
	// ErrKeyNotDefined the given key is not defined in the executor
	ErrKeyNotDefined = errors.New("Key is not defined")
	// ErrInvalidParametersCount indicates that the given action has different parameter count requirements
	ErrInvalidParametersCount = errors.New("Invalid parmaters count")
)

Functions

This section is empty.

Types

type Action

type Action func(key string, parameters ...string) error

Action defines a key driven action

type Command

type Command struct {
	Key        string
	Parameters []string
}

Command holds a key driven command instance

func ReadKeyDrivenFile

func ReadKeyDrivenFile(file string) ([]Command, error)

ReadKeyDrivenFile reads in a key driven file. A key driven file has the following format: Each lines holds one command. A command is defined by its key and parameters which are separated by a tabulator. The line ends with a new line character.

type Error

type Error struct {
	Message string
	Err     error
}

Error defines a key driven specific error

func (Error) Error

func (e Error) Error() string

type Executor

type Executor struct {
	sync.Mutex

	BeforeAction Action
	AfterAction  Action
	// contains filtered or unexported fields
}

Executor holds a key driven executor instance

func NewExecutor

func NewExecutor() *Executor

NewExecutor initialises and returns a new executor

func (*Executor) Execute

func (e *Executor) Execute(cmds []Command) error

Execute executes a set of key driven commands.

func (*Executor) MustRegister

func (e *Executor) MustRegister(key string, action Action)

MustRegister calls Register and panics if there is an error

func (*Executor) Register

func (e *Executor) Register(key string, action Action) error

Register adds a given key-action pair to the given executor

Jump to

Keyboard shortcuts

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