filter

package
v1.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package filter applies filters (`count`, `jsonpath`, `toInt`, …) to the value of a query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(items []*syntax.FilterItem, v value.Value, env *template.Env, inAssert bool) (value.Value, error)

Apply applies filters in order to v. A nil result means the last filter produced no value; a filter that receives no value fails. inAssert marks errors raised while evaluating an assert.

func ApplyOptions added in v1.5.0

func ApplyOptions(items []*syntax.FilterItem, v value.Value, env *template.Env, opts Options) (value.Value, error)

ApplyOptions is Apply with every option.

func Eval

func Eval(f *syntax.Filter, v value.Value, env *template.Env, inAssert bool) (value.Value, error)

Eval applies one filter to v (non-nil).

func EvalJSONPath

func EvalJSONPath(doc value.Value, expr *syntax.Template, env *template.Env, coerce bool) (value.Value, error)

EvalJSONPath evaluates a JSONPath template on a document. With coerce, no match gives nil, one match its value and several matches a list; without, the result is always the list of matches.

func EvalOptions added in v1.5.0

func EvalOptions(f *syntax.Filter, v value.Value, env *template.Env, opts Options) (value.Value, error)

EvalOptions is Eval with every option.

func EvalXPath

func EvalXPath(doc *xpath.Document, expr *syntax.Template, env *template.Env) (value.Value, error)

EvalXPath evaluates an XPath template on a document.

func FirstGroup

func FirstGroup(re *regexp.Regexp, s string) (string, bool)

FirstGroup returns the text of the first capture group of the leftmost match; ok is false when nothing matches or the group did not participate.

Types

type Options added in v1.5.0

type Options struct {
	// InAssert marks errors raised while evaluating an assert.
	InAssert bool
	// NoJSONPathCoercion keeps the result of a jsonpath filter a list of
	// matches, even for no match or a single one.
	NoJSONPathCoercion bool
}

Options change how filters evaluate.

Jump to

Keyboard shortcuts

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