Documentation ¶
Index ¶
- func ChainIdentity(ctx context.Context, e *executor.Event, err error) (context.Context, *executor.Event, error)
- func Error(es ...error) error
- func Error2(a, b error) error
- func IsErrorList(err error) bool
- type Chain
- type ErrorList
- type Labeler
- type Overflow
- type Rule
- func (r Rule) AndThen(next ...Rule) Rule
- func (r Rule) DropOnError() Rule
- func (r Rule) DropOnSuccess() Rule
- func (r Rule) Eval(ctx context.Context, e *executor.Event, err error, ch Chain) (context.Context, *executor.Event, error)
- func (r Rule) Handle(h events.Handler) Rule
- func (r Rule) HandleEvent(ctx context.Context, e *executor.Event) (err error)
- func (r Rule) HandleF(h events.HandlerFunc) Rule
- func (r Rule) If(b bool) Rule
- func (r Rule) OnFailure(next ...Rule) Rule
- func (r Rule) Once() Rule
- func (r Rule) RateLimit(p <-chan struct{}, over Overflow, otherwise Rule) Rule
- func (r Rule) ThenDrop() Rule
- func (r Rule) Unless(b bool) Rule
- func (r Rule) UnlessDone() Rule
- type Rules
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChainIdentity ¶
func ChainIdentity(ctx context.Context, e *executor.Event, err error) (context.Context, *executor.Event, error)
ChainIdentity is a Chain that returns the arguments as its results.
func Error ¶
Error aggregates, and then flattens, a list of errors accrued during rule processing. Returns nil if the given list of errors is empty or contains all nil errors.
func Error2 ¶
Error2 aggregates the given error params, returning nil if both are nil. Use Error2 to avoid the overhead of creating a slice when aggregating only 2 errors.
func IsErrorList ¶
IsErrorList returns true if err is a non-nil error list
Types ¶
type Chain ¶
Chain is invoked by a Rule to continue processing an event. If the chain is not invoked, no additional rules are processed.
type ErrorList ¶
type ErrorList []error
ErrorList accumulates errors that occur while processing a Chain of Rules. Accumulated errors should be appended to the end of the list. An error list should never be empty. Callers should use the package Error() func to properly accumulate (and flatten) errors.
type Labeler ¶
Labeler generates a set of strings that should be associated with metrics that are generated for the given event.
type Rule ¶
type Rule func(context.Context, *executor.Event, error, Chain) (context.Context, *executor.Event, error)
Rule is the functional adaptation of evaler. A nil Rule is valid: it is Eval'd as a noop.
func Drop ¶
func Drop() Rule
Drop aborts the Chain and returns the (context.Context, *executor.Event, error) tuple as-is.
func DropOnError ¶
func DropOnError() Rule
DropOnError returns a Rule that generates a nil event if the error state != nil
func DropOnSuccess ¶
func DropOnSuccess() Rule
func HandleF ¶
func HandleF(h events.HandlerFunc) Rule
HandleF is the functional equivalent of Handle
func Metrics ¶
Metrics generates a Rule that invokes the given harness for each event, using the labels generated by the Labeler. Panics if harness or labeler is nil.
func New ¶
New is the semantic equivalent of Rules{r1, r2, ..., rn}.Eval and exists purely for convenience.
func (Rule) AndThen ¶
AndThen returns a list of rules, beginning with the receiver, followed by DropOnError, and then all of the rules specified by the next parameter. The net effect is: execute the receiver rule and only if there is no error state, continue processing the next rules, in order.
func (Rule) DropOnError ¶
DropOnError decorates a rule by pre-checking the error state: if the error state != nil then the receiver is not invoked and (e, err) is returned; otherwise control passes to the receiving rule.
func (Rule) DropOnSuccess ¶
func (Rule) Eval ¶
func (r Rule) Eval(ctx context.Context, e *executor.Event, err error, ch Chain) (context.Context, *executor.Event, error)
Eval is a convenience func that processes a nil Rule as a noop.
func (Rule) HandleEvent ¶
HandleEvent implements events.Handler for Rule
func (Rule) HandleF ¶
func (r Rule) HandleF(h events.HandlerFunc) Rule
HandleF is the functional equivalent of Handle
func (Rule) If ¶
If only executes the receiving rule if b is true; otherwise, the returned rule is a noop.
func (Rule) RateLimit ¶
RateLimit invokes the receiving Rule if a read of chan "p" succeeds (closed chan = no rate limit), otherwise proceeds according to the specified Overflow policy. May be useful, for example, when rate-limiting logged events. Returns nil (noop) if the receiver is nil, otherwise a nil chan will normally trigger an overflow. Panics when OverflowWait is specified with a nil chan, in order to prevent deadlock. A cancelled context will trigger the "otherwise" rule.
func (Rule) ThenDrop ¶
ThenDrop executes the receiving rule, but aborts the Chain, and returns the (context.Context, *executor.Event, error) tuple as-is.
func (Rule) Unless ¶
Unless only executes the receiving rule if b is false; otherwise, the returned rule is a noop.
func (Rule) UnlessDone ¶
UnlessDone returns a decorated rule that checks context.Done: if the context has been canceled then the rule chain is aborted and the context.Err is merged with the current error state. Returns nil (noop) if the receiving Rule is nil.
type Rules ¶
type Rules []Rule
Rules is a list of rules to be processed, in order.
func (Rules) Chain ¶
Chain returns a Chain that evaluates the given Rules, in order, propagating the (context.Context, *executor.Event, error) from Rule to Rule. Chain is safe to invoke concurrently.