dispatcher

package
v0.0.0-...-c0b5b33 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrActionNotFound is returned when an action cannot be dispatched.
	ErrActionNotFound = errors.New("Action not found")
	// ErrMissingRequiredParameter is for when required parameters are missing.
	ErrMissingRequiredParameter = errors.New("Required parameters missing")
	// ErrInvalidParameter is for when parameters are supplied that are not allowed.
	ErrInvalidParameter = errors.New("Invalid parameters")
)

Functions

func TypeString

func TypeString() interface{}

TypeString is a callback that returns a *string for marshalling.

func TypeUint64

func TypeUint64() interface{}

TypeUint64 is a callback that returns a *uint64 for marshalling.

Types

type Action

type Action struct {
	RequiredParameters ParameterTable
	OptionalParameters ParameterTable
	Dispatch           Func
}

Action is the definition of the protocol action item.

type Command

type Command struct {
	UUID       string
	Resource   string
	Action     string
	Parameters map[string]json.RawMessage `json:"-"`

	Dependencies []string
	// contains filtered or unexported fields
}

Command is a unit of instruction; it contains a UUID, the unique identifier of the command, a Resource, the type of command to execute, an action, the name of the command to execute, and parameters, a collection of items that relate to the action for the purposes of execution.

Commands are typically fed to Packages, then the Package is Enqueued, Next() calls are made to yield the commands for the resource, the command is processed, FinishCommand is called to finish the command, then statuses are polled and eventually yielded.

func (Command) Parameter

func (c Command) Parameter(key string) interface{}

Parameter returns a parsed parameter or nil if no parameter exists. It is your responsibility to know the type.

type Func

type Func func(Command) error

Func is the dispatch action function. It accepts a command and the status is published back to the broker automatically as a part of the Tick() and Loop() calls.

type ParameterTable

type ParameterTable map[string]func() interface{}

ParameterTable is a map of parameter name -> type creation function. The type creation function is expected to return a type that is compatible with the JSON marshalling of the API. You must return a pointer from this call or encoding/json will vomit.

type Table

type Table map[string]Action

Table encapsulates a dispatching system that consists of actions (strings) that correspond to processed/validated properties and a processing function.

func (Table) Dispatch

func (t Table) Dispatch(c Command) error

Dispatch dispatches the Command, validating the parameters beforehand.

Jump to

Keyboard shortcuts

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