inject

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package inject contains the inject node implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InjectConfig

type InjectConfig struct {
	// Payload is the message data — interpreted per PayloadType
	Payload string `json:"payload"`
	// PayloadType selects how Payload is interpreted: "timestamp"
	// (current time in ms, Node-RED's default), "date" (same),
	// "json" (parsed), "string"/"str" (literal text), "num" (parsed
	// number), "bool" ("true"/"false"), or "env" (Payload names the
	// environment variable to read). Empty defaults to timestamp when
	// no payload is configured, json otherwise.
	PayloadType string `json:"payloadType"`
	// Topic is stamped into Metadata["topic"] on every injected message
	// (Node-RED msg.topic)
	Topic string `json:"topic"`
	// Once fires the payload immediately on deploy
	Once bool `json:"once"`
	// OnceDelay delays the Once fire by this many seconds — the
	// Node-RED field name, serialized as a number in exports (strings
	// are accepted too). 0 or absent fires immediately.
	OnceDelay interface{} `json:"onceDelay"`
	// RepeatType is the editor's repeat-mode selector:
	// "none" | "interval" | "times". It is a UI hint only — at run
	// time the populated fields decide (see repeatMode), so imported
	// configs that carry Node-RED's repeat/crontab fields still
	// schedule correctly.
	RepeatType string `json:"repeatType"`
	// Repeat is Node-RED's repeat field — the fixed interval in
	// seconds (serialized as a string in exports). Used when Interval
	// is unset.
	Repeat interface{} `json:"repeat"`
	// Crontab is Node-RED's cron field — one or more "M H * * DOW"
	// expressions (a leading seconds field is also accepted), split by
	// newline or ";". Parsed into time-of-day entries on deploy when
	// Times is empty.
	Crontab string `json:"crontab"`
	// Times is the "at a specific time" schedule — up to three
	// time-of-day entries, each with an optional weekday filter.
	Times []InjectTime `json:"times"`
	// Interval is the repeat period (0 = no repeat), in IntervalUnits
	Interval float64 `json:"interval"`
	// IntervalUnits scales Interval: "s" (default) | "min" | "hr" | "day"
	IntervalUnits string `json:"intervalUnits"`
	// Props is Node-RED's modern property list — each entry sets one
	// message property: "payload" and "topic" are the well-known ones;
	// anything else lands in Metadata. When a "payload" prop exists it
	// takes precedence over the legacy Payload/PayloadType fields.
	Props []InjectProp `json:"props"`
}

InjectConfig holds configuration for the inject node

type InjectNode

type InjectNode struct {
	*nodebase.BaseNode
	// contains filtered or unexported fields
}

InjectNode is a trigger that fires a configured payload once on deploy and/or repeatedly on an interval. Injects are fire-and-forget: no response is expected, so each message's pending entry is discarded right after injection (InjectMessage registers a pending channel keyed by msgID that nothing would otherwise resolve).

func NewInjectNode

func NewInjectNode(node nodestore.NodeInterface, config *InjectConfig, host nodebase.NodeHost) *InjectNode

NewInjectNode creates a new inject node

func (*InjectNode) Execute

Execute parses the configured payload once, then starts the firing goroutines (once-shot and/or interval ticker).

func (*InjectNode) Fire

func (n *InjectNode) Fire()

Fire injects a clone of the payload into the workflow — the host's FireInjectNode contract (a manual click on the inject button). Errors are ignored (e.g. the workflow may be undeploying). The pending response channel is discarded immediately — inject messages never get a reply.

func (*InjectNode) Stop

func (n *InjectNode) Stop() error

Stop halts the interval ticker and every scheduled timer (idempotent)

type InjectProp added in v0.7.0

type InjectProp struct {
	P  string `json:"p"`  // property name ("payload", "topic", or custom)
	V  string `json:"v"`  // literal value (per VT)
	VT string `json:"vt"` // value type: str|num|bool|json|env|date|bin|msg|flow|global|jsonata
	// HasV records whether the v key was present in the JSON document.
	// Node-RED's migrated flows carry entries without v
	// ({"p":"payload"} / {"p":"topic","vt":"str"}) meaning "use the
	// legacy top-level payload/payloadType/topic fields" — an absent
	// v must be distinguishable from an explicit empty one.
	HasV bool `json:"-"`
}

InjectProp is one entry of Node-RED's inject props array: {"p":"payload","v":"Hello","vt":"str"}.

func (*InjectProp) UnmarshalJSON added in v0.7.0

func (p *InjectProp) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the entry and records the presence of the v key for the legacy-fallback semantics documented on InjectProp.

type InjectTime added in v0.7.0

type InjectTime struct {
	// Time is "HH:MM" (24h local time); an optional ":SS" seconds
	// field is accepted for finer-grained schedules.
	Time string `json:"time"`
	// Days filters the firing weekdays (0=Sunday … 6=Saturday).
	// Empty fires every day.
	Days []int `json:"days"`
}

InjectTime is one "at a specific time" schedule entry: a wall-clock time of day plus an optional weekday filter.

Jump to

Keyboard shortcuts

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