condition

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package condition contains logical operators that, based on their configuration, return boolean values from messages under certain circumstances.

Index

Constants

This section is empty.

Variables

View Source
var Constructors = map[string]TypeSpec{}

Constructors is a map of all condition types with their specs.

View Source
var (
	ErrInvalidContentOperator = errors.New("invalid content operator type")
)

Errors for the content condition.

Functions

func Descriptions

func Descriptions() string

Descriptions returns a formatted string of collated descriptions of each type.

func SanitiseConfig

func SanitiseConfig(conf Config) (interface{}, error)

SanitiseConfig returns a sanitised version of the Config, meaning sections that aren't relevant to behaviour are removed.

Types

type And

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

And is a condition that returns the logical AND of all children.

func (*And) Check

func (c *And) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type AndConfig

type AndConfig []Config

AndConfig is a configuration struct containing fields for the And condition.

func NewAndConfig

func NewAndConfig() AndConfig

NewAndConfig returns a AndConfig with default values.

type Config

type Config struct {
	Type    string        `json:"type" yaml:"type"`
	And     AndConfig     `json:"and" yaml:"and"`
	Content ContentConfig `json:"content" yaml:"content"`
	Not     NotConfig     `json:"not" yaml:"not"`
	Or      OrConfig      `json:"or" yaml:"or"`
}

Config is the all encompassing configuration struct for all condition types.

func NewConfig

func NewConfig() Config

NewConfig returns a configuration struct fully populated with default values.

func (*Config) UnmarshalJSON

func (m *Config) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing configs that are in a slice the default values are still applied.

func (*Config) UnmarshalYAML

func (m *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing configs that are in a slice the default values are still applied.

type Content

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

Content is a condition that checks message content against logical operators.

func (*Content) Check

func (c *Content) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type ContentConfig

type ContentConfig struct {
	Operator string `json:"operator" yaml:"operator"`
	Part     int    `json:"part" yaml:"part"`
	Arg      string `json:"arg" yaml:"arg"`
}

ContentConfig is a configuration struct containing fields for the content condition.

func NewContentConfig

func NewContentConfig() ContentConfig

NewContentConfig returns a ContentConfig with default values.

type Not

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

Not is a condition that returns the opposite of another condition.

func (*Not) Check

func (c *Not) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type NotConfig

type NotConfig struct {
	*Config
}

NotConfig is a configuration struct containing fields for the Not condition.

func NewNotConfig

func NewNotConfig() NotConfig

NewNotConfig returns a NotConfig with default values.

func (NotConfig) MarshalJSON

func (m NotConfig) MarshalJSON() ([]byte, error)

MarshalJSON prints an empty object instead of nil.

func (NotConfig) MarshalYAML

func (m NotConfig) MarshalYAML() (interface{}, error)

MarshalYAML prints an empty object instead of nil.

func (*NotConfig) UnmarshalJSON

func (m *NotConfig) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing child config it is initialised.

func (*NotConfig) UnmarshalYAML

func (m *NotConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing child config it is initialised.

type Or

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

Or is a condition that returns the logical or of all children.

func (*Or) Check

func (c *Or) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type OrConfig

type OrConfig []Config

OrConfig is a configuration struct containing fields for the Or condition.

func NewOrConfig

func NewOrConfig() OrConfig

NewOrConfig returns a OrConfig with default values.

type Type

type Type interface {
	// Check tests a message against a configured condition.
	Check(msg types.Message) bool
}

Type reads a message, calculates a condition and returns a boolean.

func New

func New(conf Config, log log.Modular, stats metrics.Type) (Type, error)

New creates a condition type based on a condition configuration.

func NewAnd

func NewAnd(conf Config, log log.Modular, stats metrics.Type) (Type, error)

NewAnd returns an And processor.

func NewContent

func NewContent(conf Config, log log.Modular, stats metrics.Type) (Type, error)

NewContent returns a Content processor.

func NewNot

func NewNot(conf Config, log log.Modular, stats metrics.Type) (Type, error)

NewNot returns a Not processor.

func NewOr

func NewOr(conf Config, log log.Modular, stats metrics.Type) (Type, error)

NewOr returns an Or processor.

type TypeSpec

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

TypeSpec Constructor and a usage description for each condition type.

Jump to

Keyboard shortcuts

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