Documentation
¶
Overview ¶
Package template implements the variable substitution and templating engine used by workflow steps.
The engine resolves Go-style `{{ ... }}` expressions against an execution context that exposes workflow inputs (`{{ .input.* }}`) and prior step results (`{{ steps.<id>.* }}`). It supports both simple variable access (returning the underlying typed value) and full text-template rendering (returning a string), with a dedicated path for each so that argument passing preserves types.
Index ¶
- func MergeContexts(contexts ...map[string]interface{}) map[string]interface{}
- type Engine
- func (e *Engine) ExtractVariables(value interface{}) []string
- func (e *Engine) RenderGoTemplate(templateStr string, context map[string]interface{}) (interface{}, error)
- func (e *Engine) RenderGoTemplateTyped(templateStr string, context map[string]interface{}) (interface{}, error)
- func (e *Engine) Replace(value interface{}, context map[string]interface{}) (interface{}, error)
- func (e *Engine) ResolvePath(root interface{}, path string) (interface{}, error)
- func (e *Engine) ValidateContext(value interface{}, context map[string]interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeContexts ¶
MergeContexts merges multiple contexts into a single context Later contexts override values from earlier contexts
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine handles arg templating for service operations
func (*Engine) ExtractVariables ¶
ExtractVariables extracts all template variable names from a value
func (*Engine) RenderGoTemplate ¶
func (e *Engine) RenderGoTemplate(templateStr string, context map[string]interface{}) (interface{}, error)
RenderGoTemplate renders a full Go template with Sprig template functions This is used for complex expressions like {{ eq .input.var "value" }}
func (*Engine) RenderGoTemplateTyped ¶ added in v0.10.0
func (e *Engine) RenderGoTemplateTyped(templateStr string, context map[string]interface{}) (interface{}, error)
RenderGoTemplateTyped renders a template while preserving the actual Go type of its result, used where structured JSON output matters (workflow output output templates and jsonPath expectations).
When the template body is a single output action it is evaluated for its typed value rather than its rendered text: "{{ len .x }}" yields the number 3, "{{ eq .a .b }}" a bool, "{{ .v }}" the value's own type, and "{{ printf \"%02d\" .n }}" the string "08". Templates that mix literal text with actions, or contain several actions, render to a string because their concatenated form is inherently textual.
Crucially this never inspects the rendered text to guess a type, so a numeric-looking string such as a version "1.20" or a zero-padded "08" is preserved exactly instead of being silently coerced to a number. That guess was the source of lossy numeric coercion in earlier versions.
func (*Engine) Replace ¶
Replace replaces all template variables in a value with actual values from the context
func (*Engine) ResolvePath ¶ added in v0.10.0
ResolvePath navigates a dotted path with optional array indexing against an arbitrary root value and returns the typed value found there. It is the single path navigator shared by template variable substitution, workflow output output templates, and condition jsonPath expectations.
Supported syntax:
- object navigation: "data.field.subfield"
- array indexing: "items[0]", "data.items[2].name"
- chained indices: "matrix[0][1]"
The root may be the template context map (first segment is then a top-level variable name) or any nested value (e.g. a tool result object).
func (*Engine) ValidateContext ¶
ValidateContext ensures all required variables are present in the context