eval

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

eval

GoDoc

an evaluation framework backed by Google's Common Expression Language

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrEvalDenied    = errors.New("eval: evaluation = false")
	ErrNoExpressions = errors.New("eval: no expressions")
)

Functions

This section is empty.

Types

type Eval

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

func New

func New(expressions []string) (*Eval, error)
Example
package main

import (
	"fmt"
	"github.com/graphikDB/eval"
	"strings"
)

func main() {
	e, err := eval.New([]string{"this.email.endsWith('acme.com')"})
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	if err := e.AddExpression("this.name != ''"); err != nil {
		fmt.Println(err.Error())
		return
	}
	if err := e.Eval(eval.MapperFunc(func() map[string]interface{} {
		return map[string]interface{}{
			"name":  "bob",
			"email": "bob@acme.com",
		}
	}), eval.AllTrue); err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(strings.Join(e.Expressions(), ","))
}
Output:

this.email.endsWith('acme.com'),this.name != ''

func (*Eval) AddExpression

func (n *Eval) AddExpression(expression string) error

func (*Eval) Eval

func (n *Eval) Eval(mapper Mapper, typ EvalType) error

func (*Eval) Expressions

func (e *Eval) Expressions() []string

type EvalType

type EvalType int
const (
	AllTrue EvalType = 0
	AnyTrue EvalType = 1
)

type Mapper

type Mapper interface {
	AsMap() map[string]interface{}
}

type MapperFunc

type MapperFunc func() map[string]interface{}

func (MapperFunc) AsMap

func (m MapperFunc) AsMap() map[string]interface{}

Jump to

Keyboard shortcuts

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