goexpr

package module
v0.0.0-...-4cdd4fd Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Overview

Package goexpr provides basic expression evaluation of Go. It supports values of the following types: bool, byte, uint16, uint32, uint64, int8, int16, int32, int64, int, float32, float64, string and time.Time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayExpr

type ArrayExpr struct {
	Items []Expr
}

ArrayExpr is just a placeholder expression for grouping some other expressions together.

func (*ArrayExpr) Eval

func (e *ArrayExpr) Eval(params Params) interface{}

func (*ArrayExpr) String

func (e *ArrayExpr) String() string

func (*ArrayExpr) WalkLists

func (e *ArrayExpr) WalkLists(cb func(List))

func (*ArrayExpr) WalkOneToOneParams

func (e *ArrayExpr) WalkOneToOneParams(cb func(string))

func (*ArrayExpr) WalkParams

func (e *ArrayExpr) WalkParams(cb func(string))

type ArrayList

type ArrayList []Expr

func (ArrayList) String

func (al ArrayList) String() string

func (ArrayList) Values

func (al ArrayList) Values() []Expr

type Expr

type Expr interface {
	Eval(Params) interface{}

	// WalkParams supplies the callback with the names of any params referenced by
	// this expression.
	WalkParams(cb func(string))

	// WalkOneToOneParams supplies the callback with the names of any params whose
	// values are transformed by this expression on a one-to-one basis (i.e. every
	// input value corresponds to one distinct output value).
	WalkOneToOneParams(cb func(string))

	WalkLists(cb func(List))

	String() string
}

func Any

func Any(exprs ...Expr) Expr

Any is an expression that returns the first non-nil, non-empty string value from evaluating the exprs.

func Array

func Array(items ...Expr) Expr

Array creates a new ArrayExpr

func Binary

func Binary(operator string, left Expr, right Expr) (Expr, error)

func Boolean

func Boolean(operator string, left Expr, right Expr) (Expr, error)

Boolean accepts the operators AND, OR and returns a short-circuiting expression that evaluates left first and right second.

func Concat

func Concat(exprs ...Expr) Expr

Concat joins a list of values using the first as a delimiter.

func Constant

func Constant(val interface{}) Expr

func Decode

func Decode(exprs ...Expr) Expr

Decode compares the value of the first expression to a series of key/value pairs and returns the matching value. It optionally takes a final default value to use if none of the keys match.

func In

func In(val Expr, candidates List) Expr

func Len

func Len(source Expr) Expr

Len calculates the length of the string representation of the given value. If value is nil, returns nil.

func Not

func Not(wrapped Expr) Expr

func P

func P(wrapped Expr) Expr

P marks the wrapped expression as a One-to-One function.

func Param

func Param(name string) Expr

func Rand

func Rand() Expr

Rand returns a random float64 between 0 (inclusive) and 1 (exclusive).

func ReplaceAll

func ReplaceAll(source Expr, regex Expr, replacement Expr) Expr

ReplaceAll replaces all occurrences of the regex with the replacement.

func Split

func Split(source Expr, delim Expr, idx Expr) Expr

Split splits a given source on a delimiter and returns the value at the given index. If index is negative, it is treated relative to the end of the split list, with -1 being the very last element, -2 the 2nd to last, etc.If no value exists at the given index, this method returns nil.

func Substr

func Substr(source Expr, from Expr, length Expr) Expr

Substr takes a substring of the given source starting at the given index capped to the given length.

type List

type List interface {
	Values() []Expr
}

type MapParams

type MapParams map[string]interface{}

func (MapParams) Get

func (p MapParams) Get(name string) interface{}

type Params

type Params interface {
	Get(key string) interface{}
}

Directories

Path Synopsis
This program generates the type switch statements needed by goexpr to implement type casting
This program generates the type switch statements needed by goexpr to implement type casting
Package geo provides geolocation functions.
Package geo provides geolocation functions.
isp
Package isp provides isp lookup functions for IPv4 addresses
Package isp provides isp lookup functions for IPv4 addresses

Jump to

Keyboard shortcuts

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