Documentation ¶
Overview ¶
Package js provides facilities based on the Otto VM for parsing and executing javascript expressions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Evaluate ¶
func Evaluate(expr string, parameters interface{}, assets JavascriptAssets) (bool, error)
Evaluate evaluates the javascript expression with parameters applied. If scripts is non-nil, then the scripts will be evaluated in the expression's runtime context before the expression is evaluated.
func MatchEntities ¶
MatchEntities compiles the expressions supplied, and applies each one of them to each entity supplied. On the first match, success is recorded and the evaluator moves on to the next entity. A slice of bools is returned that is the same length as the slice of entities supplied, indicating match success or failure.
Errors are reported by logging only, with the log level determined by the severity of the error. Syntax and type errors are reported at error level, while attribute lookup errors are reported at debug level.
If the function cannot set up a javascript VM, or has issues setting vars, then the function returns a nil slice and a non-nil error.
func ParseExpressions ¶
ParseExpressions parses each JS expression and returns the first error that is encountered, or nil.
Types ¶
type EntityFilterResult ¶
EntityFilterResult is returned by EvaluateEntityFilters
type JavascriptAssets ¶
type JavascriptAssets interface { Key() string Scripts() (map[string]io.ReadCloser, error) }
type SyntaxError ¶
type SyntaxError string
SyntaxError is returned when a javascript expression could not be parsed.
func NewSyntaxError ¶
func NewSyntaxError(err string, args ...interface{}) SyntaxError
NewSyntaxError creates a new SyntaxError.
func (SyntaxError) Error ¶
func (s SyntaxError) Error() string