rulesengine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: ISC Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READY    = "READY"
	RUNNING  = "RUNNING"
	FINISHED = "FINISHED"
)

Variables

This section is empty.

Functions

func Debug

func Debug(message string)

Debug logs the message if the DEBUG environment variable contains "json-rules-engine"

func EvalEndsWith added in v0.2.0

func EvalEndsWith(a, b *ValueNode) bool

EvalEndsWith checks if the string in the first ValueNode ends with the string in the second ValueNode. Both 'a' and 'b' must be strings for the comparison to be valid. Returns true if 'a' ends with 'b', false otherwise.

func EvalEqual added in v0.2.0

func EvalEqual(a, b *ValueNode) bool

EvalEqual checks if two ValueNode instances are equal. It compares their types first, and if they match, it evaluates their values. Supported types: String, Number, Bool, Array. Returns true if both nodes have the same type and value, false otherwise.

func EvalGreaterOrEqual added in v0.2.0

func EvalGreaterOrEqual(a, b *ValueNode) bool

EvalGreaterOrEqual checks if the first ValueNode is greater than or equal to the second. Both 'a' and 'b' must be numbers for the comparison to be valid. Returns true if 'a' is greater than or equal to 'b', false otherwise.

func EvalGreaterThan added in v0.2.0

func EvalGreaterThan(a, b *ValueNode) bool

EvalGreaterThan checks if the first ValueNode is greater than the second. Both 'a' and 'b' must be numbers for the comparison to be valid. Returns true if 'a' is greater than 'b', false otherwise.

func EvalIn added in v0.2.0

func EvalIn(a, b *ValueNode) bool

EvalIn checks if a ValueNode instance is present in an array of ValueNode instances. It assumes that 'b' is an array and iterates through it to find a match with 'a'. Returns true if 'a' is found in 'b', false otherwise.

func EvalIncludes added in v0.2.0

func EvalIncludes(a, b *ValueNode) bool

EvalIncludes checks if the string in the first ValueNode contains with the string in the second ValueNode. Both 'a' and 'b' must be strings for the comparison to be valid. Returns true if 'a' ends with 'b', false otherwise.

func EvalLessThan added in v0.2.0

func EvalLessThan(a, b *ValueNode) bool

EvalLessThan checks if the first ValueNode is less than the second. Both 'a' and 'b' must be numbers for the comparison to be valid. Returns true if 'a' is less than 'b', false otherwise.

func EvalLessThanOrEqual added in v0.2.0

func EvalLessThanOrEqual(a, b *ValueNode) bool

EvalLessThanOrEqual checks if the first ValueNode is less than or equal to the second. Both 'a' and 'b' must be numbers for the comparison to be valid. Returns true if 'a' is less than or equal to 'b', false otherwise.

func EvalNotEquals added in v0.2.0

func EvalNotEquals(a, b *ValueNode) bool

EvalNotEquals checks if two ValueNode instances are not equal. It returns the negation of the EvalEqual function. Returns true if the nodes are not equal, false otherwise.

func EvalNotIn added in v0.2.0

func EvalNotIn(a, b *ValueNode) bool

EvalNotIn checks if a ValueNode instance is not present in an array of ValueNode instances. It returns the negation of EvalIn. Returns true if 'a' is not found in 'b', false otherwise.

func EvalStartsWith added in v0.2.0

func EvalStartsWith(a, b *ValueNode) bool

EvalStartsWith checks if the string in the first ValueNode starts with the string in the second ValueNode. Both 'a' and 'b' must be strings for the comparison to be valid. Returns true if 'a' starts with 'b', false otherwise.

func HashString added in v0.2.0

func HashString(data string) uint64

func IsObjectLike

func IsObjectLike(value interface{}) bool

isObjectLike checks if the value is an object-like structure

Types

type Almanac

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

Almanac is a struct that manages fact results lookup and caching within a rules engine. It allows storing raw facts, caching results of rules, and logging events (success/failure). The Almanac plays a key role in the rules engine by allowing rules to evaluate facts efficiently.

func NewAlmanac

func NewAlmanac(rf gjson.Result, options Options, initialCapacity int) *Almanac

NewAlmanac creates and returns a new Almanac instance. Params: - rf: Raw facts in the form of a gjson.Result. - options: Custom settings such as allowing undefined facts. - initialCapacity: The initial capacity to allocate for rule results. Returns a pointer to a new Almanac.

func (*Almanac) AddEvent

func (a *Almanac) AddEvent(event Event, outcome EventOutcome) error

AddEvent logs an event in the Almanac, marking it as either a success or failure. Params: - event: The event to be added. - outcome: The outcome of the event ("success" or "failure"). Returns an error if the outcome is invalid.

func (*Almanac) AddFact

func (a *Almanac) AddFact(key string, value *Fact)

func (*Almanac) AddResult

func (a *Almanac) AddResult(ruleResult *RuleResult)

AddResult adds a rule evaluation result to the Almanac. This function stores the result of a rule once it has been evaluated.

func (*Almanac) AddRuntimeFact

func (a *Almanac) AddRuntimeFact(path string, value ValueNode) error

AddRuntimeFact adds a constant fact during runtime

func (*Almanac) FactValue

func (a *Almanac) FactValue(path string) (*Fact, error)

func (*Almanac) GetEvents

func (a *Almanac) GetEvents(outcome EventOutcome) *[]Event

GetEvents retrieves events logged in the Almanac based on the specified outcome. If the outcome is "success" or "failure", it returns the events for that outcome. If the outcome is an empty string, it returns all events (success and failure combined). Params: - outcome: The desired outcome ("success", "failure", or empty string for all events). Returns a pointer to a slice of events for the specified outcome.

func (*Almanac) GetResults

func (a *Almanac) GetResults() []RuleResult

GetResults retrieves all rule results

func (*Almanac) GetValue

func (a *Almanac) GetValue(path string) (interface{}, error)

type Condition

type Condition struct {
	Priority   *int
	Name       string
	Operator   string
	Value      ValueNode
	Fact       string
	FactResult Fact
	Result     bool
	Params     map[string]interface{}
	Condition  string
	All        []*Condition
	Any        []*Condition
	Not        *Condition
}

Condition represents an individual condition within a rule in the rules engine. Conditions can compare facts to values using operators, and they can also nest other conditions. Fields: - Priority: Optional priority of the condition, must be greater than zero if set. - Name: The name of the condition. - Operator: The operator to be applied for comparison (e.g., equals, greaterThan). - Value: The value to compare the fact to. - Fact: The fact that is being evaluated in the condition. - FactResult: The result of fact evaluation. - Result: The evaluation result of the condition (true/false). - Params: Additional parameters that may affect the condition's evaluation. - Condition: Raw condition string (for debugging or custom use cases). - All, Any: Nested conditions that require all or any of the sub-conditions to be true. - Not: A nested condition that negates its result.

func (*Condition) Evaluate

func (c *Condition) Evaluate(almanac *Almanac, operatorMap map[string]Operator) (*EvaluationResult, error)

Evaluate evaluates the condition against the given almanac and operator map

func (*Condition) IsBooleanOperator

func (c *Condition) IsBooleanOperator() bool

IsBooleanOperator returns whether the operator is boolean ('all', 'any', 'not')

func (*Condition) IsConditionReference

func (c *Condition) IsConditionReference() bool

isConditionReference returns whether the condition represents a reference to a condition

func (*Condition) ToJSON

func (c *Condition) ToJSON(stringify bool) (interface{}, error)

ToJSON converts the Condition instance to a JSON string representation. Useful for serializing the condition for storage or transmission.

func (*Condition) UnmarshalJSON added in v0.2.0

func (c *Condition) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom JSON unmarshaller for the Condition struct. It validates the condition after unmarshalling to ensure it adheres to the rules. Params: - data: JSON data representing the condition. Returns an error if the condition is invalid after unmarshalling.

func (*Condition) Validate added in v0.2.0

func (c *Condition) Validate() error

Validate checks if the Condition is valid based on business rules. It verifies that if a value, fact, or operator are set, all three must be set. It also ensures that if nested conditions (Any, All, Not) are provided, no value, fact, or operator is set. Returns an error if the condition is invalid

type ConditionMap added in v0.2.0

type ConditionMap struct {
	sync.Map
}

func (*ConditionMap) Load added in v0.2.0

func (m *ConditionMap) Load(key string) (Condition, bool)

func (*ConditionMap) Store added in v0.2.0

func (m *ConditionMap) Store(key string, value Condition)

type ConditionProperties

type ConditionProperties struct {
	Fact     string                 `json:"fact"`
	Operator string                 `json:"operator"`
	Value    interface{}            `json:"value"`
	Path     *string                `json:"path,omitempty"`
	Priority *int                   `json:"priority,omitempty"`
	Params   map[string]interface{} `json:"params,omitempty"`
	Name     *string                `json:"name,omitempty"`
}

ConditionProperties represents a condition inEvaluator the rule.

func (*ConditionProperties) SetName

func (c *ConditionProperties) SetName(name string)

func (*ConditionProperties) SetPriority

func (c *ConditionProperties) SetPriority(priority int)

type DataType added in v0.2.0

type DataType int
const (
	Null DataType = iota
	Bool
	Number
	String
	Array
	Object
)

type DynamicFactCallback

type DynamicFactCallback func(almanac *Almanac, params ...interface{}) *ValueNode

type Engine

type Engine struct {
	Rules                     []*Rule
	AllowUndefinedFacts       bool
	AllowUndefinedConditions  bool
	ReplaceFactsInEventParams bool
	Operators                 map[string]Operator
	Facts                     FactMap
	Conditions                ConditionMap
	Status                    string
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(rules []*Rule, options *RuleEngineOptions) *Engine

NewEngine creates a new Engine instance with the provided rules and options. If no options are passed, default options are used. Params: - rules: A slice of rules to be added to the engine. - options: Configuration options for the engine (can be nil). Returns a pointer to the newly created Engine.

func (*Engine) AddCalculatedFact added in v0.2.0

func (e *Engine) AddCalculatedFact(path string, method DynamicFactCallback, options *FactOptions) error

AddCalculatedFact adds a calculated fact definition to the engine Params: path: The path of the fact. method: The callback function to be executed when the fact is evaluated. options: Additional options for the fact. Returns an error if the fact cannot be added.

func (*Engine) AddFact

func (e *Engine) AddFact(path string, value *ValueNode, options *FactOptions) error

AddFact adds a fact definition to the engine Params: path: The path of the fact. value: The value of the fact. options: Additional options for the fact. Returns an error if the fact cannot be added.

func (*Engine) AddOperator

func (e *Engine) AddOperator(operatorOrName interface{}, cb func(*ValueNode, *ValueNode) bool)

AddOperator adds a custom operator definition Params: - operatorOrName: The operator to be added, or the name of the operator. - cb: The callback function to be executed when the operator is evaluated.

func (*Engine) AddRule

func (e *Engine) AddRule(rule *Rule) error

AddRule adds a single rule to the rules engine. The rule is linked to the engine and stored in the engine's rules list. Params: - rule: The rule to be added to the engine. Returns an error if the rule is invalid or cannot be added.

func (*Engine) AddRuleFromMap added in v0.2.0

func (e *Engine) AddRuleFromMap(rp *RuleConfig) error

AddRuleFromMap adds a rule to the engine from a configuration map. The rule is created from the map and then added to the engine. Params: - rp: The rule configuration in map form. Returns an error if the rule configuration is invalid.

func (*Engine) AddRules added in v0.2.0

func (e *Engine) AddRules(rules []*Rule) error

AddRules adds multiple rules to the engine in a single operation. Each rule is validated and added to the engine. Params: - rules: A slice of rules to be added to the engine. Returns an error if any rule cannot be added.

func (*Engine) EvaluateRules

func (e *Engine) EvaluateRules(rules []*Rule, almanac *Almanac, ctx *ExecutionContext) error

EvaluateRules runs an array of rules Params: - rules: The rules to be evaluated. - almanac: The almanac containing facts and results. - ctx: The execution context for the rules. Returns an error if any rule evaluation fails.

func (*Engine) GetFact

func (e *Engine) GetFact(path string) *Fact

GetFact returns a fact by path Params: path: The path of the fact to be retrieved. Returns the fact if it exists, or nil if it does not.

func (*Engine) GetRules

func (e *Engine) GetRules() []*Rule

GetRules returns all rules in the engine. Returns a slice of all rules in the engine.

func (*Engine) PrioritizeRules

func (e *Engine) PrioritizeRules() [][]*Rule

PrioritizeRules iterates over the engine rules, organizing them by highest -> lowest priority Returns a 2D slice of rules, where each inner slice contains rules of the same priority

func (*Engine) RemoveCondition

func (e *Engine) RemoveCondition(name string) bool

RemoveCondition removes a condition that has previously been added to this engine Params: - name: The name of the condition to be removed. Returns true if the condition was removed, false if it was not found.

func (*Engine) RemoveFact

func (e *Engine) RemoveFact(path string) bool

RemoveFact removes a fact from the engine Params: path: The path of the fact to be removed. Returns true if the fact was removed, false if it was not found.

func (*Engine) RemoveOperator

func (e *Engine) RemoveOperator(operatorOrName interface{}) bool

RemoveOperator removes a custom operator definition Params: - operatorOrName: The operator to be removed, or the name of the operator. Returns true if the operator was removed, false if it was not found.

func (*Engine) RemoveRule

func (e *Engine) RemoveRule(rule *Rule) bool

RemoveRule removes an existing rule in the engine. Params: - r: The updated rule. Returns an error if the rule cannot be found or updated.

func (*Engine) RemoveRuleByName added in v0.2.0

func (e *Engine) RemoveRuleByName(name string) bool

RemoveRuleByName removes an existing rule in the engine by its name. Params: - name: The name of the rule to be removed. Returns true if the rule was removed, false if it was not found.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, input []byte) (map[string]interface{}, error)

func (*Engine) RunWithMap added in v0.2.0

func (e *Engine) RunWithMap(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error)

func (*Engine) Stop

func (e *Engine) Stop() *Engine

Stop stops the rules engine from running the next priority set of Rules Returns the engine instance

func (*Engine) UpdateRule

func (e *Engine) UpdateRule(r *Rule) error

UpdateRule updates an existing rule in the engine by its name. If the rule exists, it is replaced by the new version. Params: - r: The updated rule. Returns an error if the rule cannot be found or updated.

type EvaluationResult

type EvaluationResult struct {
	Result             bool        `json:"Result"`
	LeftHandSideValue  Fact        `json:"LeftHandSideValue"`
	RightHandSideValue interface{} `json:"RightHandSideValue"`
	Operator           string      `json:"Operator"`
}

type Event

type Event struct {
	Type   string
	Params map[string]interface{}
}

type EventCallback

type EventCallback func(result *RuleResult) interface{}

type EventConfig added in v0.2.0

type EventConfig struct {
	Type   string
	Params *map[string]interface{}
}

type EventHandler

type EventHandler func(event Event, almanac Almanac, ruleResult RuleResult)

EventHandler represents an event handler function.

type EventOutcome added in v0.2.0

type EventOutcome string
const (
	Success EventOutcome = "success"
	Failure EventOutcome = "failure"
)

type ExecutionContext

type ExecutionContext struct {
	context.Context
	Cancel    context.CancelFunc
	StopEarly bool
	Message   string
	Errors    []error
}

ExecutionContext holds metadata and control flags for rule execution.

func NewEvaluationContext

func NewEvaluationContext(ctx context.Context) *ExecutionContext

func (*ExecutionContext) AddError

func (c *ExecutionContext) AddError(err error)

type Fact

type Fact struct {
	Value             *ValueNode
	Path              string
	CalculationMethod DynamicFactCallback
	Cached            bool
	Priority          int
	Dynamic           bool
}

Fact represents a fact within the rules engine. It holds a value (as a ValueNode), a path identifying the fact, and optional metadata about how the value was calculated.

func NewCalculatedFact added in v0.2.0

func NewCalculatedFact(path string, method DynamicFactCallback, options *FactOptions) *Fact

NewCalculatedFact creates a new Fact instance with a dynamic calculation method. Params: path: The path identifying the fact. method: The method to calculate the fact value. options: Optional configuration options for the fact.

func NewFact

func NewFact(path string, value ValueNode, options *FactOptions) (*Fact, error)

NewFact creates a new Fact instance with a static value. Params: path: The path identifying the fact. value: The value of the fact. options: Optional configuration options for the fact.

func (*Fact) Calculate

func (f *Fact) Calculate(almanac *Almanac, params ...interface{}) *Fact

Calculate evaluates the fact value using the provided Almanac and optional parameters. If the fact is dynamic, it uses the calculation method to determine the value. Params: almanac: The Almanac instance to use for calculation. params: Optional parameters to pass to the calculation method.

type FactMap added in v0.2.0

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

FactMap is a thread-safe map used to store and manage facts in the rules engine. It provides methods for setting, loading, and deleting facts, as well as iterating over the map.

func (*FactMap) Delete added in v0.2.0

func (m *FactMap) Delete(key string)

Delete removes a fact from the FactMap using the hashed key. Params: - key: The key associated with the fact to be removed.

func (*FactMap) Load added in v0.2.0

func (m *FactMap) Load(key string) (*Fact, bool)

Load retrieves a fact from the FactMap using the hashed key. Params: - key: The key associated with the fact. Returns: - A pointer to the Fact, and a boolean indicating whether the fact was found.

func (*FactMap) LoadOrStore added in v0.2.0

func (m *FactMap) LoadOrStore(key string, value *Fact) (*Fact, bool)

LoadOrStore retrieves a fact from the FactMap if it exists, or stores the provided fact if it does not. Params: - key: The key to associate with the fact. - value: The fact to store if the key does not exist. Returns: - A pointer to the actual fact (either loaded or newly stored), and a boolean indicating if it was already present.

func (*FactMap) Range added in v0.2.0

func (m *FactMap) Range(f func(key string, value *Fact) bool)

Range iterates over all key-value pairs in the FactMap, applying the provided function to each. The function should return true to continue iteration, or false to stop. Params: - f: The function to apply to each key-value pair.

func (*FactMap) Set added in v0.2.0

func (m *FactMap) Set(key string, value *Fact)

Set stores a fact in the FactMap using the hashed key for efficient lookup. Params: - key: The key to associate with the fact. - value: The fact to store.

type FactOptions

type FactOptions struct {
	Cache    bool
	Priority int
}

type InvalidRuleError added in v0.2.0

type InvalidRuleError struct {
	Message string
	Code    string
}

InvalidRuleError represents an error for an invalid rule

func NewInvalidPriorityTypeError added in v0.2.0

func NewInvalidPriorityTypeError() *InvalidRuleError

func NewInvalidPriorityValueError added in v0.2.0

func NewInvalidPriorityValueError() *InvalidRuleError

func NewInvalidRuleError added in v0.2.0

func NewInvalidRuleError(message string, code string) *InvalidRuleError

func NewPriorityNotSetError added in v0.2.0

func NewPriorityNotSetError() *InvalidRuleError

func (*InvalidRuleError) Error added in v0.2.0

func (e *InvalidRuleError) Error() string

type Operator

type Operator struct {
	Name               string
	Callback           func(a, b *ValueNode) bool
	FactValueValidator func(factValue *ValueNode) bool
}

Operator defines a function that compares two ValueNodes and returns a boolean result. Operators are used in conditions to perform comparisons like equals, greater than, etc.

func DefaultOperators

func DefaultOperators() []Operator

DefaultOperators returns a slice of default operators

func NewOperator

func NewOperator(name string, cb func(a, b *ValueNode) bool, factValueValidator func(factValue *ValueNode) bool) (*Operator, error)

NewOperator adds a new operator to the engine. Params: - name: The name of the operator. - op: The operator function to be added.

func (*Operator) Evaluate

func (o *Operator) Evaluate(a, b *ValueNode) bool

Evaluate takes the fact result and compares it to the condition 'value' using the callback function. Params: - a: The fact value. - b: The condition value. Returns true if the condition is met, false otherwise.

type Options

type Options struct {
	AllowUndefinedFacts *bool // Optional flag to allow undefined facts
}

Options defines the optional settings for the Almanac. It includes a flag to allow or disallow the use of undefined facts during rule evaluation.

type Rule

type Rule struct {
	Priority   int
	Name       string
	Conditions Condition
	RuleEvent  Event
	Engine     *Engine
	// contains filtered or unexported fields
}

Rule represents a rule in the engine. A rule has conditions, actions, and a priority level that determines its order of execution.

func NewRule

func NewRule(config *RuleConfig) (*Rule, error)

NewRule creates a new Rule instance

func (*Rule) Evaluate

func (r *Rule) Evaluate(ctx *ExecutionContext, almanac *Almanac) (*RuleResult, error)

Evaluate checks if the conditions of the rule are satisfied based on the given facts. Params: - almanac: The almanac containing facts for evaluation. Returns true if the rule's conditions are met, false otherwise.

func (*Rule) GetConditions

func (r *Rule) GetConditions() *Condition

GetConditions returns the event object

func (*Rule) GetEngine

func (r *Rule) GetEngine() *Engine

GetEngine returns the engine object

func (*Rule) GetEvent

func (r *Rule) GetEvent() Event

GetEvent returns the event object

func (*Rule) GetPriority

func (r *Rule) GetPriority() int

GetPriority returns the priority

func (*Rule) SetEngine

func (r *Rule) SetEngine(engine *Engine)

SetEngine sets the engine to run the rules under

func (*Rule) ToJSON

func (r *Rule) ToJSON(stringify bool) (interface{}, error)

ToJSON converts the rule to a JSON-friendly structure

type RuleConfig added in v0.2.0

type RuleConfig struct {
	Name       string      `json:"name"`
	Priority   *int        `json:"priority"`
	Conditions Condition   `json:"conditions"`
	Event      EventConfig `json:"event"`
	OnSuccess  func(result *RuleResult) interface{}
	OnFailure  func(result *RuleResult) interface{}
}

func (*RuleConfig) UnmarshalJSON added in v0.2.0

func (r *RuleConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom JSON unmarshaller for RuleConfig to ensure proper unmarshaling of Condition

type RuleEngineOptions

type RuleEngineOptions struct {
	AllowUndefinedFacts       bool
	AllowUndefinedConditions  bool
	ReplaceFactsInEventParams bool
}

func DefaultRuleEngineOptions

func DefaultRuleEngineOptions() *RuleEngineOptions

DefaultRuleEngineOptions returns a default set of options for the rules engine. This includes whether undefined facts or conditions are allowed, and if facts should be replaced in event parameters.

type RuleProperties

type RuleProperties struct {
	Conditions TopLevelCondition `json:"conditions"`
	Event      Event             `json:"event"`
	Name       *string           `json:"name,omitempty"`
	Priority   *int              `json:"priority,omitempty"`
	OnSuccess  *EventHandler     `json:"onSuccess,omitempty"`
	OnFailure  *EventHandler     `json:"onFailure,omitempty"`
}

RuleProperties represents the properties of a rule.

type RuleResult

type RuleResult struct {
	Conditions Condition
	Event      Event
	Priority   int
	Name       string
	Result     *bool
	// contains filtered or unexported fields
}

RuleResult represents the result of a rule evaluation

func NewRuleResult

func NewRuleResult(conditions Condition, event Event, priority int, name string) *RuleResult

NewRuleResult creates a new RuleResult instance

func (*RuleResult) ResolveEventParams

func (rr *RuleResult) ResolveEventParams(almanac *Almanac) error

ResolveEventParams resolves the event parameters using the given almanac

func (*RuleResult) SetResult

func (rr *RuleResult) SetResult(result *bool)

SetResult sets the result of the rule evaluation

func (*RuleResult) ToJSON

func (rr *RuleResult) ToJSON(stringify bool) (interface{}, error)

ToJSON converts the rule result to a JSON-friendly structure

type TopLevelCondition

type TopLevelCondition struct {
	All       *[]ConditionProperties `json:"all,omitempty"`
	Any       *[]ConditionProperties `json:"any,omitempty"`
	Not       *ConditionProperties   `json:"not,omitempty"`
	Condition *string                `json:"condition,omitempty"`
	Name      *string                `json:"name,omitempty"`
	Priority  *int                   `json:"priority,omitempty"`
}

TopLevelCondition represents the top-level condition, which can be AllConditions, AnyConditions, NotConditions, or ConditionReference.

type UndefinedFactError

type UndefinedFactError struct {
	Message string
	Code    string
}

UndefinedFactError represents an error for an undefined fact

func NewUndefinedFactError

func NewUndefinedFactError(message string) *UndefinedFactError

NewUndefinedFactError creates a new UndefinedFactError instance

func (*UndefinedFactError) Error

func (e *UndefinedFactError) Error() string

Error implements the error interface for UndefinedFactError

type ValueNode added in v0.2.0

type ValueNode struct {
	Type   DataType
	Bool   bool
	Number float64
	String string
	Array  []ValueNode
	Object map[string]ValueNode
}

ValueNode represents a value used in conditions and comparisons. It supports types such as strings, numbers, booleans, arrays, and null.

func NewValueFromGjson added in v0.2.0

func NewValueFromGjson(result gjson.Result) *ValueNode

NewValueFromGjson converts a gjson.Result into a ValueNode. It handles various data types such as null, string, number, boolean, and arrays. Params: - result: The gjson.Result to be converted. Returns a pointer to a ValueNode representing the result.

func (*ValueNode) IsArray added in v0.2.0

func (v *ValueNode) IsArray() bool

func (*ValueNode) IsBool added in v0.2.0

func (v *ValueNode) IsBool() bool

func (*ValueNode) IsNull added in v0.2.0

func (v *ValueNode) IsNull() bool

func (*ValueNode) IsNumber added in v0.2.0

func (v *ValueNode) IsNumber() bool

func (*ValueNode) IsObject added in v0.2.0

func (v *ValueNode) IsObject() bool

func (*ValueNode) IsString added in v0.2.0

func (v *ValueNode) IsString() bool

func (*ValueNode) Raw added in v0.2.0

func (v *ValueNode) Raw() interface{}

func (*ValueNode) SameType added in v0.2.0

func (v *ValueNode) SameType(other *ValueNode) bool

func (*ValueNode) UnmarshalJSON added in v0.2.0

func (v *ValueNode) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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