Documentation
¶
Overview ¶
Package bexpr is an implementation of a generic boolean expression evaluator. The general goal is to be able to evaluate some expression against some arbitrary data and get back a boolean indicating if the data was matched by the expression
Index ¶
- func CoerceBool(value string) (interface{}, error)
- func CoerceFloat32(value string) (interface{}, error)
- func CoerceFloat64(value string) (interface{}, error)
- func CoerceInt64(value string) (interface{}, error)
- func CoerceUint64(value string) (interface{}, error)
- type Evaluator
- type Filter
- type Option
- type ValueTransformationHookFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoerceBool ¶
CoerceBool conforms to the FieldValueCoercionFn signature and can be used to convert the raw string value of an expression into a `bool`
func CoerceFloat32 ¶
CoerceFloat32 conforms to the FieldValueCoercionFn signature and can be used to convert the raw string value of an expression into an `float32`
func CoerceFloat64 ¶
CoerceFloat64 conforms to the FieldValueCoercionFn signature and can be used to convert the raw string value of an expression into an `float64`
func CoerceInt64 ¶
CoerceInt64 conforms to the FieldValueCoercionFn signature and can be used to convert the raw string value of an expression into an `int64`
func CoerceUint64 ¶
CoerceUint64 conforms to the FieldValueCoercionFn signature and can be used to convert the raw string value of an expression into an `int64`
Types ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
func CreateEvaluator ¶
CreateEvaluator is used to create and configure a new Evaluator, the expression will be used by the evaluator when evaluating against any supplied datum. The following Option types are supported: WithHookFn, WithMaxExpressions, WithTagName, WithUnknownValue.
func (*Evaluator) Evaluate ¶
Evaluate attempts to match the configured expression against the supplied datum. It returns a value indicating if a match was found and any error that occurred. If an error is returned, the value indicating a match will be false.
func (*Evaluator) Expression ¶ added in v0.1.14
Expression can be used to return the initial expression used to create the Evaluator.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
func CreateFilter ¶
Creates a filter to operate on the given data type. The data type passed can be either be a container type (map, slice or array) or the element type. For example, if you want to filter a []Foo then the data type to pass here is either []Foo or just Foo. If no expression is provided the nil filter will be returned but is not an error. This is done to allow for executing the nil filter which is just a no-op
type Option ¶
type Option func(*options)
Option - how Options are passed as arguments
func WithHookFn ¶ added in v0.1.7
func WithHookFn(fn ValueTransformationHookFn) Option
WithHookFn sets a HookFn to be called on the Go data under evaluation and all subfields, indexes, and values recursively. That makes it easier for the JSON Pointer to not match exactly the Go value being evaluated (for example, when using protocol buffers' well-known types).
func WithLocalVariable ¶ added in v0.1.13
WithLocalVariable add a local variable that can either point to another path that will be resolved when the local variable is referenced or to a known value that will be used directly.
func WithMaxExpressions ¶ added in v0.1.3
func WithTagName ¶ added in v0.1.5
WithTagName indictes what tag to use instead of the default "bexpr"
func WithUnknownValue ¶ added in v0.1.11
func WithUnknownValue(val interface{}) Option
WithUnknownValue sets a value that is used for any unknown keys. Normally, bexpr will error on any expressions with unknown keys. This can be set to instead use a specificed value whenever an unknown key is found. For example, this might be set to the empty string "".
type ValueTransformationHookFn ¶ added in v0.1.7
type ValueTransformationHookFn = pointerstructure.ValueTransformationHookFn
ValueTransformationHookFn provides a way to translate one reflect.Value to another during evaluation by bexpr. This facilitates making Go structures appear in a way that matches the expected JSON Pointers used for evaluation. This is helpful, for example, when working with protocol buffers' well-known types.