messagefilter

package
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package messagefilter is a small smart-filter expression engine for Kafka messages (task MSG-24). It compiles a predicate expression into a Filter that can be evaluated against api.Message values.

Grammar (recursive descent, no external deps):

expr       := orExpr
orExpr     := andExpr ( ("OR"|"or"|"||") andExpr )*
andExpr    := comparison ( ("AND"|"and"|"&&") comparison )*
comparison := "(" expr ")" | field OP operand
field      := key | value | partition | offset | header.NAME | headers.NAME
OP         := contains | == | != | > | < | >= | <=
operand    := "quoted" | 'quoted' | number | bareword

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Test

func Test(expr string, samples []api.Message) (results []bool, compileErr error, evalErr error)

Test compiles expr and evaluates it against each sample, returning per-sample results. compileErr is set if compilation failed (results nil then). evalErr is set if any sample fails to evaluate.

Types

type Filter

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

Filter is a compiled smart-filter expression.

func Compile

func Compile(expr string) (*Filter, error)

Compile parses expr into a Filter. Empty/whitespace expr => error.

func (*Filter) Eval

func (f *Filter) Eval(m api.Message) (bool, error)

Eval evaluates the compiled filter against a message. err is non-nil only on evaluation errors (e.g. a numeric comparison against a non-numeric field value).

func (*Filter) Expr

func (f *Filter) Expr() string

Expr returns the original expression string.

func (*Filter) ID

func (f *Filter) ID() string

ID returns a deterministic short id derived from a hash of the expression (same expression => same id).

Jump to

Keyboard shortcuts

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