expeval

package module
v0.0.0-...-8bbdc38 Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 5 Imported by: 0

README

go-expeval

Expression evaluation for golang

expeval


import "github.com/tkuchiki/go-expeval"

Usage

type ExpEval
type ExpEval struct {
}

A ExpEval is expression evaluation

func NewExpEval
func NewExpEval(name, path string) *ExpEval

NewExpEval returns the *expeval.ExpEval

func (*ExpEval) Eval
func (e *ExpEval) Eval(expr string, values map[string]interface{}) (interface{}, error)

Eval returns the evaluated value(interface{})

func (*ExpEval) EvalToBool
func (e *ExpEval) EvalToBool(expr string, values map[string]interface{}) (bool, error)

EvalToBool returns the evaluated value(bool)

func (*ExpEval) EvalToFloat64
func (e *ExpEval) EvalToFloat64(expr string, values map[string]interface{}) (float64, error)

EvalToFloat64 returns the evaluated value(float64)

func (*ExpEval) EvalToInt64
func (e *ExpEval) EvalToInt64(expr string, values map[string]interface{}) (int64, error)

EvalToInt64 returns the evaluated value(int64)

func (*ExpEval) EvalToString
func (e *ExpEval) EvalToString(expr string, values map[string]interface{}) (string, error)

EvalToString returns the evaluated value(string)

func (*ExpEval) EvalToUint64
func (e *ExpEval) EvalToUint64(expr string, values map[string]interface{}) (uint64, error)

EvalToUint64 returns the evaluated value(uint64)

Examples

package main

import (
	"fmt"
	"github.com/tkuchiki/go-expeval"
	"log"
)

func main() {
	// same types.NewPackage("main", "main")
	eval := expeval.NewExpEval("main", "main")

	values := map[string]interface{}{
		"foo": 5,
	}
	tv, err := eval.Eval(`foo < 10 && foo > 1`, values)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tv.(bool))

	values = map[string]interface{}{
		"foo": 10,
	}
	b, err := eval.EvalToBool(`foo < 10 && foo > 1`, values)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(b)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpEval

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

A ExpEval is expression evaluation

func NewExpEval

func NewExpEval(name, path string) *ExpEval

NewExpEval returns the *expeval.ExpEval

func (*ExpEval) Eval

func (e *ExpEval) Eval(expr string, values map[string]interface{}) (interface{}, error)

Eval returns the evaluated value(interface{})

func (*ExpEval) EvalToBool

func (e *ExpEval) EvalToBool(expr string, values map[string]interface{}) (bool, error)

EvalToBool returns the evaluated value(bool)

func (*ExpEval) EvalToFloat64

func (e *ExpEval) EvalToFloat64(expr string, values map[string]interface{}) (float64, error)

EvalToFloat64 returns the evaluated value(float64)

func (*ExpEval) EvalToInt64

func (e *ExpEval) EvalToInt64(expr string, values map[string]interface{}) (int64, error)

EvalToInt64 returns the evaluated value(int64)

func (*ExpEval) EvalToString

func (e *ExpEval) EvalToString(expr string, values map[string]interface{}) (string, error)

EvalToString returns the evaluated value(string)

func (*ExpEval) EvalToUint64

func (e *ExpEval) EvalToUint64(expr string, values map[string]interface{}) (uint64, error)

EvalToUint64 returns the evaluated value(uint64)

Jump to

Keyboard shortcuts

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