{"modulePath":"github.com/dracory/nodebase","version":"v0.11.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package switchnode\n\nPackage switchnode contains the switch node implementation.\n\n## Types\n\n```go\ntype SwitchConfig struct {\n\tRules []nodebase.SwitchRule `json:\"rules\"`\n\tMode  string                `json:\"mode\"` // first | all (default \"first\")\n\t// Otherwise adds a dedicated port after the last rule output; a\n\t// message matching no rule is routed there (Node-RED \"otherwise\").\n\tOtherwise bool `json:\"otherwise\"`\n\t// CheckAll is Node-RED's serialized evaluate-all flag (\"true\"/\n\t// \"false\") — used when Mode is unset\n\tCheckAll string `json:\"checkall\"`\n\t// Repair is Node-RED's sequence-repair flag: a parts sequence is\n\t// buffered until complete, then each output's surviving subset is\n\t// re-emitted with parts.index/count rewritten\n\tRepair bool `json:\"repair\"`\n}\n```\nSwitchConfig holds configuration for the switch node\n\n```go\ntype SwitchNode struct {\n\t*nodebase.BaseNode\n\t// contains filtered or unexported fields\n}\n```\nSwitchNode 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.\n\n```go\nfunc NewSwitchNode(node nodestore.NodeInterface, config *SwitchConfig, host ...nodebase.NodeHost) *SwitchNode\n```\nNewSwitchNode creates a new switch node. host is optional — without it, rules reading flow/global context or env vars simply miss.\n\n```go\nfunc (n *SwitchNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)\n```\nExecute 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.\n\n```go\nfunc (n *SwitchNode) SelectPorts(input, output nodestore.MessageInterface) []string\n```\nSelectPorts 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.\n\n```go\nfunc (n *SwitchNode) Validate() error\n```\nValidate rejects bad rule configuration at deploy time (project policy: unsupported features fail loudly, not silently at message time).\n\n","path":"github.com/dracory/nodebase/switch","name":"switchnode","synopsis":"Package switchnode contains the switch node implementation.","isRedistributable":true}
