expr

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package expr evaluates the expressions and {{ }} templates of a workflow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Refs added in v1.18.0

func Refs(v any, name string) (keys []string, dynamic bool)

Refs returns the names that the templates in v read from the object name, as name.key or name['key']. v is a string, or a map or array of them at any depth, as a value under vars is. dynamic is true when a template reads the object in a way whose key cannot be known before it runs, such as name[k] or the object as a whole, so that it may read any key. keys come in the order they are first read, a map's values in the order of its sorted keys.

An expression that does not parse reads nothing here; evaluating it reports the error.

Types

type Expr

type Expr struct{}

Expr evaluates expressions and templates against an environment such as a step's context.

func (*Expr) Eval

func (e *Expr) Eval(input string, env any) (any, error)

func (*Expr) EvalOrEvalTemplate

func (e *Expr) EvalOrEvalTemplate(input string, env any) (string, error)

func (*Expr) EvalTemplate

func (e *Expr) EvalTemplate(input string, env any) (string, error)

EvalTemplate replaces each {{ }} template in input with the value of its expression. A template that does not compile or fails to run is an error naming the template, and no string is returned: a value with the error written into it would otherwise be sent on, as a URL or a header, as if it were right.

func (*Expr) EvalTemplateMap

func (e *Expr) EvalTemplateMap(input map[string]any, env any) (map[string]any, error)

EvalTemplateMap evaluates every template in the values of input, at any depth, keeping the type of a value that is a single template. The errors of all the values that could not be evaluated are joined, each as a *FieldError naming its value. The map is returned with them too, holding nil where a value could not be evaluated, so that a caller can still see the values that could, such as credentials to hide from the errors.

func (*Expr) EvalTemplateWithTypePreservation

func (e *Expr) EvalTemplateWithTypePreservation(input string, env any) (any, error)

func (*Expr) Options

func (e *Expr) Options(env any) []ex.Option

Options builds the expr options used to compile every workflow expression.

Two guards that used to live here have been removed because neither did anything. ex.DisableBuiltin had no effect on all / any / one / filter / map / count: expr's parser recognises those as predicate builtins before it looks at the disabled set (parser.go, the `predicates` table), so the calls were dead and the functions have always been reachable. A per-key blocklist that filtered the environment was equally inert, because the filtered copy only ever reached the type checker while ex.Run receives the caller's env, and enforcing it would have broken the documented way of reading credentials into `vars`.

What still bounds an expression is the length check in validateExpression, the evaluation timeout in executeWithTimeout, and the argument limits on the functions registered below.

type FieldError added in v1.18.0

type FieldError struct {
	Path string
	Err  error
}

FieldError is an error in the value under a key of a map evaluated by EvalTemplateMap. Path names the value from the top of that map, as in headers.authorization or items[0].name.

func (*FieldError) Error added in v1.18.0

func (e *FieldError) Error() string

func (*FieldError) Unwrap added in v1.18.0

func (e *FieldError) Unwrap() error

type TemplateError added in v1.18.0

type TemplateError struct {
	Template string // The template as written, braces included
	Err      error  // Why it could not be evaluated
}

TemplateError is a {{ }} template that could not be evaluated.

func (*TemplateError) Error added in v1.18.0

func (e *TemplateError) Error() string

func (*TemplateError) Unwrap added in v1.18.0

func (e *TemplateError) Unwrap() error

Jump to

Keyboard shortcuts

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