goldfish_re

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Goldfish-RE

Reactive and Embeddable rules engine library written in pure Go!.

This rules engine has been thought to trigger automatically an event letting you know that a condition from your ruleset has been satisfied by some updated fact into your context.

The evaluation algorithm is RETE based with focus on evaluation and memory using a Trie struct to improve its performance.

Supported data types

The rule engines expose different data types to work with:

  • String: This is a well known string type
  • Number: A number is a representation of an integer value. In this case is a wrapper for a int64 data type
  • Float: Floats are also numeric types. They represent the decimal numbers implemented as float64
  • Boolean: The boolean are useful to assert a condition as true or false
  • Date: Represents a time.Time data type

For more details, please read the documentation

Installation

To install the library into your project please run:

go install github.com/darksubmarine/goldfish-re

Examples

License

Apache License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidDataType invalid data type
	ErrInvalidDataType = errors.New("invalid data type")

	// ErrInvalidValueType invalid value type
	ErrInvalidValueType = errors.New("invalid value type")

	// ErrContextUpdateRecovered recovered context update after panic
	ErrContextUpdateRecovered = errors.New("recovered context update after panic")

	// ErrRegisteredObjectMustBePointer error registering object must be a pointer
	ErrRegisteredObjectMustBePointer = errors.New("error registering object must be a pointer")

	// ErrMalformedTag malformed tag
	ErrMalformedTag = errors.New("malformed tag")

	// ErrEmptyThenSentence empty 'then' sentence in rule
	ErrEmptyThenSentence = errors.New("empty 'then' sentence in rule")

	// ErrEmptyConditionList the rule must contains at least one condition
	ErrEmptyConditionList = errors.New("the rule must contains at least one condition")

	// ErrNilObject nil object
	ErrNilObject = errors.New("nil object")

	// ErrFactNotFound fact not found
	ErrFactNotFound = errors.New("fact not found")

	// ErrFactInvalidType fact is registered with different data type
	ErrFactInvalidType = errors.New("fact is registered with different data type")
)

Functions

func Builder

func Builder() *builder_

Builder builder_ constructor

func CalendarDateUTC

func CalendarDateUTC(y, m, d int) time.Time

func CalendarFullDateUTC

func CalendarFullDateUTC(y, m, d, h, mm, s, ns int) time.Time

func YearUTC

func YearUTC(y int) time.Time

Types

type Boolean

type Boolean = *booleanFact

Boolean data type used to declare user Facts. This is an alias to *booleanFact

func NewBoolean

func NewBoolean(object, attribute string, value bool) Boolean

NewBoolean is the Boolean fact constructor

type Context

type Context interface {
	GetString(fact string) (String, error)
	GetNumber(fact string) (Number, error)
	GetFloat(fact string) (Float, error)
	GetBoolean(fact string) (Boolean, error)
	GetDate(fact string) (Date, error)
	Get(fact string) (interface{}, bool)
	GetObject(object string) (interface{}, bool)
	ForEach(fn func(fact string, value interface{}))
	Feedback(func(tx *Tx))
}

Context interface that can be accessed from onActivation function

type Date

type Date = *dateFact

Date data type used to declare user Facts. This is an alias to *dateFact the data type is a wrapper of time.Time

func NewDate

func NewDate(object, attribute string, value time.Time) Date

NewDate is the Date fact constructor

type FactsContext

type FactsContext interface {
	WithMaxIterations(i int)
	Register(object interface{}) error
	RegisterString(object interface{}, attribute String) error
	RegisterNumber(object interface{}, attribute Number) error
	RegisterFloat(object interface{}, attribute Float) error
	RegisterBoolean(object interface{}, attribute Boolean) error
	RegisterDate(object interface{}, attribute Date) error
	SetString(attribute interface{}, value string) error
	SetNumber(attribute interface{}, value int64) error
	SetFloat(attribute interface{}, value float64) error
	SetBoolean(attribute interface{}, value bool) error
	SetDate(attribute interface{}, value time.Time) error
	Update(fn func(tx *Tx)) error
}

FactsContext interface that is returned when a Context is created from a ruleset

type Float

type Float = *floatFact

Float data type used to declare user Facts. This is an alias to *floatFact

func NewFloat

func NewFloat(object, attribute string, value float64) Float

NewFloat is the Float fact constructor

type Number

type Number = *numberFact

Number data type used to declare user Facts. This is an alias to *numberFact

func NewNumber

func NewNumber(object, attribute string, value int64) Number

NewNumber is the Number fact constructor

type Ruleset

type Ruleset interface {
	AddRule(r *_rule)
	Context() *factContext
}

Ruleset interface to expose available actions to do with a ruleset

type String

type String = *stringFact

String data type used to declare user Facts. This is an alias to *stringFact

func NewString

func NewString(object, attribute, value string) String

NewString is the String fact constructor

type Tx

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

Tx transaction struct

func (*Tx) Error

func (tx *Tx) Error(err error)

Error exported method to let users add custom errors on context.Update method

func (*Tx) SetBoolean

func (tx *Tx) SetBoolean(object Boolean, value bool)

SetBoolean preset the given fact with the given bool value

func (*Tx) SetDate

func (tx *Tx) SetDate(object Date, value time.Time)

SetDate preset the given fact with the given time.Time value

func (*Tx) SetFloat

func (tx *Tx) SetFloat(object Float, value float64)

SetFloat preset the given fact with the given float64 value

func (*Tx) SetNumber

func (tx *Tx) SetNumber(object Number, value int64)

SetNumber preset the given fact with the given int64 value

func (*Tx) SetString

func (tx *Tx) SetString(object String, value string)

SetString preset the given fact with the given string value

Directories

Path Synopsis
examples
advanced command
starterkit command

Jump to

Keyboard shortcuts

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