expr

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 5 Imported by: 0 modules, 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 expr is the data layer's expression evaluator. Pipeline operators that need conditional logic (filter `where:`, derive `compute:`, join `on:`) compile expressions once at Build time and evaluate them per item at Fetch / Subscribe time.

The package wraps github.com/expr-lang/expr behind a tiny Go interface so the rest of the codebase doesn't import the library directly. Centralizing this boundary lets us:

  • Swap evaluators later (cel-go, govaluate, custom) without touching every operator that compiles expressions.
  • Concentrate built-in functions (now, len, lower, upper, …) in one place — operator implementations get a consistent set of helpers automatically.
  • Format error messages uniformly so configs surface compile and runtime errors the same way regardless of evaluator.

Like the rest of the data layer, this package never imports anything TUI-related. A CI check enforces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eval

func Eval(p *Program, env any) (any, error)

Eval runs the program against env (typically the item being evaluated, exposed at the top level — so `status.phase` works without an `item.` prefix). Pipeline-level parameters are passed separately via EvalWithParams; this convenience form is for callers that don't have params (or only have the item).

func EvalBool

func EvalBool(p *Program, env any) (bool, error)

EvalBool runs the program and coerces the result to bool. Used by predicate operators (filter `where:`, future `if` clauses).

Coercion rules: real bool returns directly; nil and "" → false; non-zero numbers → true; non-empty strings (besides "") → true. Any other type errors so a misspelled field doesn't silently pass the filter.

func EvalBoolWithParams

func EvalBoolWithParams(p *Program, env any, params map[string]string) (bool, error)

EvalBoolWithParams is EvalBool with pipeline-bound params available as `params.<name>` in the expression env.

func EvalWithParams

func EvalWithParams(p *Program, env any, params map[string]string) (any, error)

EvalWithParams runs the program with the item AND a separate pipeline-bound parameters map. Params show up as `params.<name>` in the expression; item fields stay at the top level. Pass nil for params when the operator has none.

Types

type Program

type Program struct {
	// contains filtered or unexported fields
}

Program is a compiled expression ready for evaluation. Compile once, run many — building once at pipeline.Build keeps per-item evaluation cheap.

func Compile

func Compile(src string) (*Program, error)

Compile parses and compiles src. The returned Program can be Eval'd against any environment (map[string]any or struct). Compilation errors include the original expression so config debugging is straightforward.

Jump to

Keyboard shortcuts

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