Documentation
¶
Overview ¶
Package expression provides a declarative expression language for data transformation and querying within Δ-controller pipelines.
The expression system supports JSONPath-based field access, boolean logic, arithmetic operations, string manipulation, and Kubernetes-specific operations like label selectors. Expressions are serialized as JSON and can be embedded in pipeline specifications.
Expression operations include:
- Field access: "$.metadata.name", "$.spec.containers[0].image".
- Boolean logic: @and, @or, @not, @eq, @ne, @lt, @gt.
- String operations: @concat, @split, @replace, @regex.
- Arithmetic: @add, @sub, @mul, @div, @mod.
- Collections: @len, @contains, @in, @keys, @values.
- Kubernetes: @selector for label matching.
Example usage:
expr := Expression{
Op: "@eq",
Arg: []Expression{
{Op: "@string", Literal: "$.metadata.labels.app"},
{Op: "@string", Literal: "nginx"},
},
}
result, err := expr.Evaluate(EvalCtx{Object: obj})
Index ¶
- func AsBinaryBoolList(d any) ([]bool, error)
- func AsBinaryFloatList(d any) ([]float64, error)
- func AsBinaryIntList(d any) ([]int64, error)
- func AsBinaryIntOrFloatList(d any) ([]int64, []float64, reflect.Kind, error)
- func AsBinaryStringList(d any) ([]string, error)
- func AsBool(d any) (bool, error)
- func AsBoolList(d any) ([]bool, error)
- func AsFloat(d any) (float64, error)
- func AsFloatList(d any) ([]float64, error)
- func AsInt(d any) (int64, error)
- func AsIntList(d any) ([]int64, error)
- func AsIntOrFloat(d any) (int64, float64, reflect.Kind, error)
- func AsIntOrFloatList(d any) ([]int64, []float64, reflect.Kind, error)
- func AsList(d any) ([]any, error)
- func AsMap(d any) (map[string]any, error)
- func AsObject(d any) (map[string]any, error)
- func AsObjectList(d any) ([]map[string]any, error)
- func AsObjectOrObjectList(d any) ([]map[string]any, error)
- func AsString(d any) (string, error)
- func AsStringList(d any) ([]string, error)
- func GetJSONPath(ctx EvalCtx, key string) (any, error)
- func GetJSONPathRaw(query string, object any) (any, error)
- func IsList(d any) bool
- func MatchLabels(labelMap map[string]any, selectorMap map[string]any) (bool, error)
- func SetJSONPath(ctx EvalCtx, key string, value, data any) error
- func SetJSONPathRaw(key string, value, target any) error
- func SetJSONPathRawExp(keyExp *Expression, value, data any) error
- type ErrExpression
- type ErrInvalidArguments
- type ErrUnmarshal
- type EvalCtx
- type Expression
- func (e *Expression) DeepCopyInto(out *Expression)
- func (e *Expression) Evaluate(ctx EvalCtx) (any, error)
- func (e *Expression) GetLiteralBool() (bool, error)
- func (e *Expression) GetLiteralFloat() (float64, error)
- func (e *Expression) GetLiteralInt() (int64, error)
- func (e *Expression) GetLiteralList() ([]any, error)
- func (e *Expression) GetLiteralMap() (map[string]any, error)
- func (e *Expression) GetLiteralString() (string, error)
- func (e *Expression) MarshalJSON() ([]byte, error)
- func (e *Expression) String() string
- func (e *Expression) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsBinaryBoolList ¶
func AsBinaryFloatList ¶
func AsBinaryIntList ¶
func AsBinaryIntOrFloatList ¶
func AsBinaryStringList ¶
func AsBoolList ¶
func AsFloatList ¶
func AsObjectOrObjectList ¶
AsObjectOrObjectList returns an object or an expression list.
func AsStringList ¶
func GetJSONPath ¶
GetJSONPath evaluates a string op that may or may not be a JSONPath expession.
func GetJSONPathRaw ¶
GetJSONPathRaw evaluates a JSONPath expression on the specified object and returns the result or an error.
func MatchLabels ¶
MatchLabels implements a Kubernetes style label matcher.
func SetJSONPath ¶
SetJSONPath overwrites the data in-place with the given value at the given key. Leaves the rest of the data unchanged.
func SetJSONPathRaw ¶
SetJSONPathRaw sets a key (possibly represented with a JSONPath expression) to a value (can also be a JSONPath expression, which will be evaluated using the object argument) in the given data structure.
func SetJSONPathRawExp ¶
func SetJSONPathRawExp(keyExp *Expression, value, data any) error
SetJSONPathRawExp is the same as SetJSONPathRaw but takes the key as a string expression.
Types ¶
type ErrExpression ¶
type ErrExpression = error
ErrExpression is a custom error.
func NewExpressionError ¶
func NewExpressionError(e *Expression, err error) ErrExpression
NewExpressionError creates a new custom error.
type ErrInvalidArguments ¶
type ErrInvalidArguments = error
ErrInvalidArguments is a custom error.
func NewInvalidArgumentsError ¶
func NewInvalidArgumentsError(content string) ErrInvalidArguments
NewInvalidArgumentsError creates a new custom error.
type ErrUnmarshal ¶
type ErrUnmarshal = error
ErrUnmarshal is a custom error.
func NewUnmarshalError ¶
func NewUnmarshalError(kind, content string) ErrUnmarshal
NewUnmarshalError creates a new custom error.
type Expression ¶
type Expression struct {
Op string
Arg *Expression
Literal any
}
Expression defines a single expression op.
func AsExpOrExpList ¶
func AsExpOrExpList(d any) ([]Expression, error)
AsExpOrExpList returns an expression or an expression list.
func NewJSONPathGetExpression ¶
func NewJSONPathGetExpression(key string) Expression
NewJSONPathGetExpression creates an expression that, when evaluated on an object, will return the value at the given key.
func NewJSONPathSetExpression ¶
func NewJSONPathSetExpression(key string, value any) (Expression, error)
NewJSONPathSetExpression creates an expression that, when evaluated on an object, will set the value at the given key to the value.
func NewLiteralExpression ¶
func NewLiteralExpression(value any) (Expression, error)
NewLiteralExpression creates a new literal expression with the given argument.
func (*Expression) DeepCopyInto ¶
func (e *Expression) DeepCopyInto(out *Expression)
DeepCopyInto deep-copies an expression.
func (*Expression) Evaluate ¶
func (e *Expression) Evaluate(ctx EvalCtx) (any, error)
Evaluate processes an expression.
func (*Expression) GetLiteralBool ¶
func (e *Expression) GetLiteralBool() (bool, error)
GetLiteralBool returns a liteal bool from an expression.
func (*Expression) GetLiteralFloat ¶
func (e *Expression) GetLiteralFloat() (float64, error)
GetLiteralFloat returns a liteal floating point number from an expression.
func (*Expression) GetLiteralInt ¶
func (e *Expression) GetLiteralInt() (int64, error)
GetLiteralInt returns a liteal integer from an expression.
func (*Expression) GetLiteralList ¶
func (e *Expression) GetLiteralList() ([]any, error)
GetLiteralList returns a liteal list from an expression.
func (*Expression) GetLiteralMap ¶
func (e *Expression) GetLiteralMap() (map[string]any, error)
GetLiteralMap returns a liteal set of key-value pairs from an expression.
func (*Expression) GetLiteralString ¶
func (e *Expression) GetLiteralString() (string, error)
GetLiteralString returns a liteal string from an expression.
func (*Expression) MarshalJSON ¶
func (e *Expression) MarshalJSON() ([]byte, error)
UnmarshalJSON serializes an expression into JSON.
func (*Expression) UnmarshalJSON ¶
func (e *Expression) UnmarshalJSON(b []byte) error
UnmarshalJSON de-serializes an expression from JSON.