condition

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Eq      = "=="
	Ne      = "!="
	Gt      = ">"
	Lt      = "<"
	Ge      = ">="
	Le      = "<="
	Exists  = "exists"
	In      = "in"
	Matches = "matches"
	Type    = "type"
	And     = "and"
	Or      = "or"
	Not     = "not"
)

Condition operator constants.

Variables

This section is empty.

Functions

func CheckType

func CheckType(v any, typeName string) bool

CheckType reports whether v matches the given type name.

func Evaluate

func Evaluate(root reflect.Value, c *Condition) (bool, error)

Evaluate evaluates a condition against a root value.

Types

type Condition

type Condition struct {
	Path  string       `json:"p,omitempty"`
	Op    string       `json:"o"` // see operator constants above
	Value any          `json:"v,omitempty"`
	Sub   []*Condition `json:"apply,omitempty"` // Sub-conditions for logical operators (and, or, not)
}

Condition represents a serializable predicate for conditional application.

func FromPredicate

func FromPredicate(m map[string]any) *Condition

FromPredicate parses a JSON Patch predicate wire-format map into a Condition. This is the inverse of Condition.ToPredicate.

func (*Condition) ToPredicate

func (c *Condition) ToPredicate() map[string]any

ToPredicate returns a JSON-serializable map representing the condition in the JSON Patch predicate wire format. This is the inverse of FromPredicate.

Jump to

Keyboard shortcuts

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