Help us shape the future of Go! Take the 2026 Go Developer Survey

filter

package
v1.21.83 Latest Latest
Warning

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

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

Documentation

Overview

Package filter applies filter expressions to api table rows, tree nodes and map rows through the configured Adapter.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingVariable = errors.New("missing variable")

ErrMissingVariable is wrapped by adapters when a predicate references a variable absent from the evaluated row or node.

View Source
var ErrNoAdapter = errors.New("no filter adapter configured: call celfilter.Use() from github.com/flanksource/clicky/api/filter/celfilter or gomplatefilter.Use() from github.com/flanksource/clicky/api/filter/gomplatefilter")

Functions

func MapRows added in v1.21.81

func MapRows(rows []map[string]any, expression string) ([]map[string]any, error)

func SetAdapter added in v1.21.83

func SetAdapter(a Adapter)

func TableRows

func TableRows(rows []api.PrettyDataRow, filterExpr string) ([]api.PrettyDataRow, error)

TableRows filters table rows using an expression. Field values are injected directly into the expression context (no "row." prefix).

func TreeNode

func TreeNode(node api.TreeNode, filterExpr string) (api.TreeNode, error)

TreeNode recursively filters tree nodes using an expression. Field values from node content are injected directly into the expression context.

func Validate added in v1.21.83

func Validate(expression string) error

Validate checks expression syntax with the configured adapter.

Types

type Adapter added in v1.21.83

type Adapter interface {
	Validate(expression string) error
	// Compile prepares expression for variables shaped like sample. A nil value
	// in sample declares a variable without a fixed type.
	Compile(expression string, sample map[string]any) (Predicate, error)
}

Adapter is the expression engine behind TableRows, TreeNode and MapRows. The core package ships none: applications opt in with celfilter.Use() or gomplatefilter.Use() so library consumers don't compile an engine they never call.

type MapPredicate added in v1.21.81

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

func CompileMapPredicate added in v1.21.81

func CompileMapPredicate(keys []string, expression string) (*MapPredicate, error)

CompileMapPredicate compiles expression for map rows with the given keys. Values are untyped; "row" holds every column so keys with spaces stay addressable.

func (*MapPredicate) Match added in v1.21.81

func (predicate *MapPredicate) Match(row map[string]any) (bool, error)

type Predicate added in v1.21.83

type Predicate interface {
	Match(variables map[string]any) (bool, error)
}

func Compile added in v1.21.83

func Compile(expression string, sample map[string]any) (Predicate, error)

Compile prepares expression with the configured adapter; see Adapter.Compile.

Directories

Path Synopsis
Package celfilter is the CEL engine for github.com/flanksource/clicky/api/filter.
Package celfilter is the CEL engine for github.com/flanksource/clicky/api/filter.
Package gomplatefilter adds the flanksource/gomplate CEL function set to filter expressions.
Package gomplatefilter adds the flanksource/gomplate CEL function set to filter expressions.

Jump to

Keyboard shortcuts

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