cond

package
v4.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCondition

func MarshalCondition[T any](c Condition[T]) (any, error)

MarshalCondition returns a serializable surrogate (struct or map) for the condition. To get the JSON bytes, pass the result to json.Marshal.

func MarshalConditionAny

func MarshalConditionAny(c any) (any, error)

Types

type Condition

type Condition[T any] interface {
	// Evaluate evaluates the condition against the given value.
	Evaluate(v *T) (bool, error)

	// MarshalJSON returns the JSON representation of the condition.
	MarshalJSON() ([]byte, error)

	InternalCondition
}

Condition represents a logical check against a value of type T.

func And

func And[T any](conds ...Condition[T]) Condition[T]

And returns a condition that represents a logical AND of multiple conditions.

func Contains

func Contains[T any](p, val string) Condition[T]

Contains returns a condition that checks if the string value at the path contains the given substring.

func ContainsFold

func ContainsFold[T any](p, val string) Condition[T]

ContainsFold returns a condition that checks if the string value at the path contains the given substring (case-insensitive).

func ConvertFromCondSurrogate

func ConvertFromCondSurrogate[T any](s any) (Condition[T], error)

func Defined

func Defined[T any](p string) Condition[T]

Defined returns a condition that checks if the value at the path is defined.

func EndsWith

func EndsWith[T any](p, val string) Condition[T]

EndsWith returns a condition that checks if the string value at the path ends with the given suffix.

func EndsWithFold

func EndsWithFold[T any](p, val string) Condition[T]

EndsWithFold returns a condition that checks if the string value at the path ends with the given suffix (case-insensitive).

func Eq

func Eq[T any](p string, val any) Condition[T]

Eq returns a condition that checks if the value at the path is equal to the given value.

func EqFold

func EqFold[T any](p string, val any) Condition[T]

EqFold returns a condition that checks if the value at the path is equal to the given value (case-insensitive).

func EqualField

func EqualField[T any](path1, path2 string) Condition[T]

EqualField returns a condition that checks if the value at path1 is equal to the value at path2.

func EqualFieldFold

func EqualFieldFold[T any](path1, path2 string) Condition[T]

EqualFieldFold returns a condition that checks if the value at path1 is equal to the value at path2 (case-insensitive).

func Greater

func Greater[T any](p string, val any) Condition[T]

Greater returns a condition that checks if the value at the path is greater than the given value.

func GreaterEqual

func GreaterEqual[T any](p string, val any) Condition[T]

GreaterEqual returns a condition that checks if the value at the path is greater than or equal to the given value.

func GreaterEqualField

func GreaterEqualField[T any](path1, path2 string) Condition[T]

GreaterEqualField returns a condition that checks if the value at path1 is greater than or equal to the value at path2.

func GreaterField

func GreaterField[T any](path1, path2 string) Condition[T]

GreaterField returns a condition that checks if the value at path1 is greater than the value at path2.

func In

func In[T any](p string, values ...any) Condition[T]

In returns a condition that checks if the value at the path is one of the given values.

func InFold

func InFold[T any](p string, values ...any) Condition[T]

InFold returns a condition that checks if the value at the path is one of the given values (case-insensitive).

func Less

func Less[T any](p string, val any) Condition[T]

Less returns a condition that checks if the value at the path is less than the given value.

func LessEqual

func LessEqual[T any](p string, val any) Condition[T]

LessEqual returns a condition that checks if the value at the path is less than or equal to the given value.

func LessEqualField

func LessEqualField[T any](path1, path2 string) Condition[T]

LessEqualField returns a condition that checks if the value at path1 is less than or equal to the value at path2.

func LessField

func LessField[T any](path1, path2 string) Condition[T]

LessField returns a condition that checks if the value at path1 is less than the value at path2.

func Log

func Log[T any](message string) Condition[T]

Log returns a condition that logs the given message during evaluation.

func Matches

func Matches[T any](p, pattern string) Condition[T]

Matches returns a condition that checks if the string value at the path matches the given regex pattern.

func MatchesFold

func MatchesFold[T any](p, pattern string) Condition[T]

MatchesFold returns a condition that checks if the string value at the path matches the given regex pattern (case-insensitive).

func Ne

func Ne[T any](p string, val any) Condition[T]

Ne returns a condition that checks if the value at the path is not equal to the given value.

func NeFold

func NeFold[T any](p string, val any) Condition[T]

NeFold returns a condition that checks if the value at the path is not equal to the given value (case-insensitive).

func Not

func Not[T any](c Condition[T]) Condition[T]

Not returns a condition that represents a logical NOT of a condition.

func NotEqualField

func NotEqualField[T any](path1, path2 string) Condition[T]

NotEqualField returns a condition that checks if the value at path1 is not equal to the value at path2.

func NotEqualFieldFold

func NotEqualFieldFold[T any](path1, path2 string) Condition[T]

NotEqualFieldFold returns a condition that checks if the value at path1 is not equal to the value at path2 (case-insensitive).

func Or

func Or[T any](conds ...Condition[T]) Condition[T]

Or returns a condition that represents a logical OR of multiple conditions.

func ParseCondition

func ParseCondition[T any](expr string) (Condition[T], error)

ParseCondition parses a string expression into a Condition[T] tree.

func StartsWith

func StartsWith[T any](p, val string) Condition[T]

StartsWith returns a condition that checks if the string value at the path starts with the given prefix.

func StartsWithFold

func StartsWithFold[T any](p, val string) Condition[T]

StartsWithFold returns a condition that checks if the string value at the path starts with the given prefix (case-insensitive).

func Type

func Type[T any](p, typeName string) Condition[T]

Type returns a condition that checks if the value at the path has the given type.

func Undefined

func Undefined[T any](p string) Condition[T]

Undefined returns a condition that checks if the value at the path is undefined.

func UnmarshalCondition

func UnmarshalCondition[T any](data []byte) (Condition[T], error)

type InternalCondition

type InternalCondition interface {
	EvaluateAny(v any) (bool, error)
	Paths() []string
	WithRelativePath(prefix string) InternalCondition
}

InternalCondition is an internal interface for efficient evaluation without reflection.

Jump to

Keyboard shortcuts

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