Documentation
¶
Overview ¶
Package switchnode contains the switch node implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SwitchConfig ¶
type SwitchConfig struct {
Rules []nodebase.SwitchRule `json:"rules"`
Mode string `json:"mode"` // first | all (default "first")
// Otherwise adds a dedicated port after the last rule output; a
// message matching no rule is routed there (Node-RED "otherwise").
Otherwise bool `json:"otherwise"`
// CheckAll is Node-RED's serialized evaluate-all flag ("true"/
// "false") — used when Mode is unset
CheckAll string `json:"checkall"`
// Repair is Node-RED's sequence-repair flag: a parts sequence is
// buffered until complete, then each output's surviving subset is
// re-emitted with parts.index/count rewritten
Repair bool `json:"repair"`
}
SwitchConfig holds configuration for the switch node
type SwitchNode ¶
SwitchNode routes the message to one of several output ports based on rules evaluated against the payload — the Node-RED switch equivalent. The node itself is a pass-through; routing happens via SelectPorts.
func NewSwitchNode ¶
func NewSwitchNode(node nodestore.NodeInterface, config *SwitchConfig, host ...nodebase.NodeHost) *SwitchNode
NewSwitchNode creates a new switch node. host is optional — without it, rules reading flow/global context or env vars simply miss.
func (*SwitchNode) Execute ¶
func (n *SwitchNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)
Execute passes the input through unchanged — routing is done by the host via SelectPorts. With repair enabled and a parts sequence, the message is buffered until the sequence completes, then each output's subset is re-emitted with repaired parts and this message dropped.
func (*SwitchNode) SelectPorts ¶
func (n *SwitchNode) SelectPorts(input, output nodestore.MessageInterface) []string
SelectPorts evaluates the configured rules in order against the input payload and returns the matching output port keys. "first" mode stops at the first match; "all" returns every matching port. No match returns an empty slice — the message dies at this node.
func (*SwitchNode) Validate ¶
func (n *SwitchNode) Validate() error
Validate rejects bad rule configuration at deploy time (project policy: unsupported features fail loudly, not silently at message time).