Documentation
¶
Overview ¶
Package change contains the change node implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangeConfig ¶
type ChangeConfig struct {
Rules []ChangeRule `json:"rules"`
}
ChangeConfig holds configuration for the change node
type ChangeNode ¶
ChangeNode mutates msg.Payload via an ordered list of rules, the equivalent of Node-RED's change node. A failing rule is skipped so one bad rule does not abort the flow.
func NewChangeNode ¶
func NewChangeNode(node nodestore.NodeInterface, config *ChangeConfig, host ...nodebase.NodeHost) *ChangeNode
NewChangeNode creates a new change node. host is optional — without it, rules touching flow/global context or env vars resolve to absent values.
func (*ChangeNode) Execute ¶
func (n *ChangeNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)
Execute applies each configured rule in order and returns the mutated payload
type ChangeRule ¶
type ChangeRule struct {
Op string `json:"op"` // set | delete | move | replace
Field string `json:"field"`
// FieldType selects where Field resolves: "" (or "msg") is the
// message, "flow"/"global" is the context store — Node-RED's pt.
FieldType string `json:"fieldType,omitempty"`
Value string `json:"value"`
// Pattern and Replacement drive the "replace" op: the field value
// is stringified, regexp.ReplaceAllString(Pattern, Replacement) is
// applied ($1/${name} backrefs supported), and the result is
// written back — Node-RED's t:"change" rule.
Pattern string `json:"pattern,omitempty"`
Replacement string `json:"replacement,omitempty"`
// ValueType is Node-RED's tot: how Value is interpreted for "set"
// — "str" (default), "num", "bool", "json", "msg" (read the
// value from a message property path, same as FromField), "env"
// (environment variable name), "flow"/"global" (context key), or
// "jsonata" (a JSONata expression evaluated against the message).
ValueType string `json:"valueType,omitempty"`
// FromField, when set, takes the value from a message path
// (msg.topic, payload.user, …) instead of the literal Value —
// Node-RED's set-with-tot:"msg".
FromField string `json:"fromField,omitempty"`
}
ChangeRule is a single ordered mutation applied to the message. Field is a dotted path; "payload" (or empty) targets msg.Payload, a "msg." prefix (e.g. "msg.statusCode") targets msg-level properties stored in Metadata — Node-RED's msg.statusCode/msg.headers equivalent — and anything else is a path inside msg.Payload.