routers

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: AGPL-3.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const TypeFirst string = "first"

TypeFirst is the type for FirstRouters

View Source
const TypeRandom string = "random"

TypeRandom is the type for a random router

View Source
const TypeRandomOnce string = "random_once"

TypeRandomOnce is the constant for our random once router

View Source
const TypeSwitch string = "switch"

TypeSwitch is the constant for our switch router

Variables

This section is empty.

Functions

func ReadRouter added in v0.11.0

func ReadRouter(data json.RawMessage) (flows.Router, error)

ReadRouter reads a router from the given JSON

func RegisterType added in v0.11.0

func RegisterType(name string, initFunc func() flows.Router)

RegisterType registers a new type of router

Types

type BaseRouter

type BaseRouter struct {
	Type_ string `json:"type" validate:"required"`

	// ResultName_ is the name of the which the result of this router should be saved as (if any)
	ResultName_ string `json:"result_name,omitempty"`
}

BaseRouter is the base class for all our router classes

func (*BaseRouter) EnumerateDependencies added in v0.29.0

func (r *BaseRouter) EnumerateDependencies(localization flows.Localization, include func(assets.Reference))

EnumerateDependencies enumerates all dependencies on this object

func (*BaseRouter) EnumerateResultNames added in v0.29.0

func (r *BaseRouter) EnumerateResultNames(include func(string))

EnumerateResultNames enumerates all result names on this object

func (*BaseRouter) EnumerateTemplates added in v0.29.0

func (r *BaseRouter) EnumerateTemplates(localization flows.Localization, include func(string))

EnumerateTemplates enumerates all expressions on this object and its children

func (*BaseRouter) ResultName

func (r *BaseRouter) ResultName() string

ResultName returns the name which the result of this router should be saved as (if any)

func (*BaseRouter) RewriteTemplates added in v0.29.0

func (r *BaseRouter) RewriteTemplates(localization flows.Localization, rewrite func(string) string)

RewriteTemplates rewrites all templates on this object and its children

func (*BaseRouter) Type added in v0.22.0

func (r *BaseRouter) Type() string

Type returns the type of this router

type Case

type Case struct {
	UUID        utils.UUID     `json:"uuid"                 validate:"required"`
	Type        string         `json:"type"                 validate:"required"`
	Arguments   []string       `json:"arguments,omitempty"`
	OmitOperand bool           `json:"omit_operand,omitempty"`
	ExitUUID    flows.ExitUUID `json:"exit_uuid"            validate:"required"`
}

Case represents a single case and test in our switch

func NewCase added in v0.23.0

func NewCase(uuid utils.UUID, type_ string, arguments []string, omitOperand bool, exitUUID flows.ExitUUID) *Case

NewCase creates a new case

func (*Case) EnumerateDependencies added in v0.29.0

func (c *Case) EnumerateDependencies(localization flows.Localization, include func(assets.Reference))

EnumerateDependencies enumerates all dependencies on this object and its children

func (*Case) EnumerateResultNames added in v0.29.0

func (c *Case) EnumerateResultNames(include func(string))

EnumerateResultNames enumerates all result names on this object

func (*Case) EnumerateTemplates added in v0.29.0

func (c *Case) EnumerateTemplates(localization flows.Localization, include func(string))

EnumerateTemplates enumerates all expressions on this object and its children

func (*Case) Inspect added in v0.29.0

func (c *Case) Inspect(inspect func(flows.Inspectable))

Inspect inspects this object and any children

func (*Case) LocalizationUUID added in v0.29.0

func (c *Case) LocalizationUUID() utils.UUID

LocalizationUUID gets the UUID which identifies this object for localization

func (*Case) RewriteTemplates added in v0.29.0

func (c *Case) RewriteTemplates(localization flows.Localization, rewrite func(string) string)

RewriteTemplates rewrites all templates on this object and its children

type FirstRouter

type FirstRouter struct {
	BaseRouter
}

FirstRouter is a simple router that always takes the first exit

func NewFirstRouter added in v0.4.0

func NewFirstRouter(resultName string) *FirstRouter

func (*FirstRouter) Inspect added in v0.29.0

func (r *FirstRouter) Inspect(inspect func(flows.Inspectable))

Inspect inspects this object and any children

func (*FirstRouter) PickRoute

func (r *FirstRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (*string, flows.Route, error)

PickRoute always picks the first exit if available for this router

func (*FirstRouter) Validate

func (r *FirstRouter) Validate(exits []flows.Exit) error

Validate validates the arguments on this router

type RandomOnceRouter

type RandomOnceRouter struct {
	BaseRouter
	Exit flows.ExitUUID `json:"exit"     validate:"required"`
}

RandomOnceRouter exits of our exits once (randomly) before taking exit

func NewRandomOnceRouter added in v0.4.0

func NewRandomOnceRouter(exit flows.ExitUUID, resultName string) *RandomOnceRouter

func (*RandomOnceRouter) Inspect added in v0.29.0

func (r *RandomOnceRouter) Inspect(inspect func(flows.Inspectable))

Inspect inspects this object and any children

func (*RandomOnceRouter) PickRoute

func (r *RandomOnceRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (*string, flows.Route, error)

PickRoute will attempt to take a random exit it hasn't taken before. If all exits have been taken, then it will take the exit specified in it's Exit parameter

func (*RandomOnceRouter) Validate

func (r *RandomOnceRouter) Validate(exits []flows.Exit) error

Validate validates the parameters on this router

type RandomRouter

type RandomRouter struct {
	BaseRouter
}

RandomRouter is a router which will exit out a random exit

func NewRandomRouter added in v0.4.0

func NewRandomRouter(resultName string) *RandomRouter

func (*RandomRouter) Inspect added in v0.29.0

func (r *RandomRouter) Inspect(inspect func(flows.Inspectable))

Inspect inspects this object and any children

func (*RandomRouter) PickRoute

func (r *RandomRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (*string, flows.Route, error)

PickRoute picks a route randomly from our available exits

func (*RandomRouter) Validate

func (r *RandomRouter) Validate(exits []flows.Exit) error

Validate validates that the fields on this router are valid

type SwitchRouter

type SwitchRouter struct {
	BaseRouter
	Default flows.ExitUUID `json:"default_exit_uuid"   validate:"omitempty,uuid4"`
	Operand string         `json:"operand"             validate:"required"`
	Cases   []*Case        `json:"cases"`
}

SwitchRouter is a router which allows specifying 0-n cases which should each be tested in order, following whichever case returns true, or if none do, then taking the default exit

func NewSwitchRouter added in v0.4.0

func NewSwitchRouter(defaultExit flows.ExitUUID, operand string, cases []*Case, resultName string) *SwitchRouter

NewSwitchRouter creates a new switch router

func (*SwitchRouter) EnumerateDependencies added in v0.29.0

func (r *SwitchRouter) EnumerateDependencies(localization flows.Localization, include func(assets.Reference))

EnumerateDependencies enumerates all dependencies on this object and its children

func (*SwitchRouter) EnumerateResultNames added in v0.29.0

func (r *SwitchRouter) EnumerateResultNames(include func(string))

EnumerateResultNames enumerates all result names on this object

func (*SwitchRouter) EnumerateTemplates added in v0.29.0

func (r *SwitchRouter) EnumerateTemplates(localization flows.Localization, include func(string))

EnumerateTemplates enumerates all expressions on this object and its children

func (*SwitchRouter) Inspect added in v0.29.0

func (r *SwitchRouter) Inspect(inspect func(flows.Inspectable))

Inspect inspects this object and any children

func (*SwitchRouter) PickRoute

func (r *SwitchRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (*string, flows.Route, error)

PickRoute evaluates each of the tests on our cases in order, returning the exit for the first case which evaluates to a true. If no cases evaluate to true, then the default exit (if specified) is returned

func (*SwitchRouter) RewriteTemplates added in v0.29.0

func (r *SwitchRouter) RewriteTemplates(localization flows.Localization, rewrite func(string) string)

RewriteTemplates rewrites all templates on this object and its children

func (*SwitchRouter) Validate

func (r *SwitchRouter) Validate(exits []flows.Exit) error

Validate validates the arguments for this router

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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