Documentation
¶
Overview ¶
Package pipeline provides the TemplateEngine and ExprEngine used to evaluate {{ }} and ${ } expressions in pipeline step configs. It has no dependency on the module monolith: its only workflow-internal import is interfaces/.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigLookup func(key string) (string, bool)
ConfigLookup is a function variable that returns the value for a config key. It must be set by the module package at init time so that the "config" template function can access the global config registry without importing module/. If nil, the "config" template function always returns an empty string.
Functions ¶
func ContainsExpr ¶
ContainsExpr reports whether s contains a ${ } expression block.
func PreprocessTemplate ¶
PreprocessTemplate rewrites dot-access chains containing hyphens into index syntax so that Go's text/template parser does not treat hyphens as minus. For example: {{ .steps.my-step.field }} → {{ (index .steps "my-step" "field") }}
func ResolveExprBlocks ¶
func ResolveExprBlocks(s string, pc *interfaces.PipelineContext, ee *ExprEngine) (string, error)
ResolveExprBlocks replaces all ${ ... } blocks in s by evaluating each expression against pc. Returns the substituted string or the first error.
func TemplateFuncMap ¶
TemplateFuncMap returns the function map available in pipeline templates.
Types ¶
type ExprEngine ¶
type ExprEngine struct{}
ExprEngine evaluates ${ ... } expressions against a PipelineContext. It provides a simpler, more natural syntax than Go templates:
${ body.name } – field access
${ upper(body.name) } – function call
${ steps["parse"]["id"] } – hyphenated step names
${ x == "active" && y > 5 } – boolean / comparison
${ "Hello " + body.name } – string concat
func (*ExprEngine) Evaluate ¶
func (e *ExprEngine) Evaluate(exprStr string, pc *interfaces.PipelineContext) (string, error)
Evaluate evaluates a single expr expression string (without ${ } delimiters) against the provided PipelineContext and returns the result as a string. Nil results become empty strings; all other values are formatted with %v.
type SetStep ¶
type SetStep struct {
// contains filtered or unexported fields
}
SetStep sets template-resolved values in the pipeline context.
func (*SetStep) Execute ¶
func (s *SetStep) Execute(_ context.Context, pc *interfaces.PipelineContext) (*interfaces.StepResult, error)
Execute resolves template expressions in the configured values and returns them as the step output.
type StepFactory ¶
type StepFactory func(name string, config map[string]any, app modular.Application) (interfaces.PipelineStep, error)
StepFactory creates a PipelineStep from its name and config. This matches module.StepFactory but lives in the pipeline package so that external plugins can construct steps without importing the module monolith.
func NewSetStepFactory ¶
func NewSetStepFactory() StepFactory
NewSetStepFactory returns a StepFactory that creates SetStep instances.
type TemplateEngine ¶
type TemplateEngine struct{}
TemplateEngine resolves {{ .field }} expressions against a PipelineContext.
func NewTemplateEngine ¶
func NewTemplateEngine() *TemplateEngine
NewTemplateEngine creates a new TemplateEngine.
func (*TemplateEngine) Resolve ¶
func (te *TemplateEngine) Resolve(tmplStr string, pc *interfaces.PipelineContext) (string, error)
Resolve evaluates a template string against a PipelineContext. Supports two syntaxes that may be mixed in a single string:
- Go templates: {{ .field }}, {{ upper .name }}, etc.
- Expr expressions: ${ body.name }, ${ upper(name) }, etc.
${ } blocks are evaluated first; the resulting string is then passed through the Go template engine if any {{ }} blocks remain.
If the string contains neither {{ }} nor ${ }, it is returned as-is.
Missing key behaviour (direct map access via {{ .steps.foo.bar }}):
- When pc.StrictTemplates is true (Option A), any reference to a missing map key causes an immediate error via missingkey=error, surfacing typos as failures.
- When pc.StrictTemplates is false (the default, Option C), a missing key resolves to the zero value AND a WARN log is emitted via pc.Logger (or slog.Default() when no logger is set) so that the silent failure is visible without breaking existing pipelines.
NOTE: Strict template mode applies to both direct map key resolution (missingkey=error) and the step/trigger helper functions. Missing keys accessed via {{ step "name" "field" }} or {{ trigger "key" }} also return an error in strict mode.
func (*TemplateEngine) ResolveMap ¶
func (te *TemplateEngine) ResolveMap(data map[string]any, pc *interfaces.PipelineContext) (map[string]any, error)
ResolveMap evaluates all string values in a map that contain {{ }} expressions. Non-string values and nested maps/slices are processed recursively.