expression

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package expression provides support for evaluating expressions in Aptomi, with support for caching compiled expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a thread-safe cache of compiled expressions

func NewCache

func NewCache() *Cache

NewCache creates a new thread-safe Cache

func (*Cache) EvaluateAsBool

func (cache *Cache) EvaluateAsBool(expressionStr string, params *Parameters) (bool, error)

EvaluateAsBool evaluates boolean expression given a set of parameters. If an compiled expression already exists in cache, it will be used. Otherwise it will get compiled and added to the cache before evaluating the expression. This method is thread-safe and can be called concurrently from multiple goroutines.

type Expression

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

Expression struct contains expression string as well as its compiled version

func NewExpression

func NewExpression(expressionStr string) (*Expression, error)

NewExpression compiles an expression and returns the result in Expression struct Parameter expressionStr must follow syntax defined by https://github.com/Knetic/govaluate

func (*Expression) EvaluateAsBool

func (expression *Expression) EvaluateAsBool(params *Parameters) (bool, error)

EvaluateAsBool evaluates a compiled boolean expression given a set of named parameters

type Parameters

type Parameters map[string]interface{}

Parameters is a set of named parameters for the expression

func NewParams

func NewParams(stringParams map[string]string, structParams map[string]interface{}) *Parameters

NewParams creates a new set of named Parameters. Each parameter should be int, bool, or string.

Jump to

Keyboard shortcuts

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