function

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package function provides basic functions which implement Funcer interface

Index

Constants

View Source
const (
	// FuncIn is the function/operator keyword in
	FuncIn = "in"
	// FuncBetween is the function/operator keyword between
	FuncBetween = "between"
	// FuncOverlap is the function/operator keyword overlap
	FuncOverlap = "overlap"

	// FuncAnd is the function/operator keyword and
	FuncAnd = "and"
	// FuncOr is the function/operator keyword or
	FuncOr = "or"
	// FuncNot is the function/operator keyword not
	FuncNot = "not"
	// OperatorAnd is the function/operator keyword &
	OperatorAnd = "&"
	// OperatorOr is the function/operator keyword |
	OperatorOr = "|"
	// OperatorNot is the function/operator keyword !
	OperatorNot = "!"

	// FuncEqual is the function/operator keyword eq
	FuncEqual = "eq"
	// FuncNotEqual is the function/operator keyword ne
	FuncNotEqual = "ne"
	// FuncGreaterThan is the function/operator keyword gt
	FuncGreaterThan = "gt"
	// FuncLessThan is the function/operator keyword lt
	FuncLessThan = "lt"
	// FuncGreaterThanOrEqualTo is the function/operator keyword ge
	FuncGreaterThanOrEqualTo = "ge"
	// FuncLessThanOrEqualTo is the function/operator keyword le
	FuncLessThanOrEqualTo = "le"
	// OperatorEqual is the function/operator keyword =
	OperatorEqual = "="
	// OperatorNotEqual is the function/operator keyword !=
	OperatorNotEqual = "!="
	// OperatorGreaterThan is the function/operator keyword >
	OperatorGreaterThan = ">"
	// OperatorLessThan is the function/operator keyword <
	OperatorLessThan = "<"
	// OperatorGreaterThanOrEqualTo is the function/operator keyword >=
	OperatorGreaterThanOrEqualTo = ">="
	// OperatorLessThanOrEqualTo is the function/operator keyword <=
	OperatorLessThanOrEqualTo = "<="

	// FuncModulo is the function/operator keyword mod
	FuncModulo = "mod"
	// OperatorModulo is the function/operator keyword %
	OperatorModulo = "%"

	// OperatorAdd is the function/operator keyword +
	OperatorAdd = "+"
	// OperatorSubtract is the function/operator keyword -
	OperatorSubtract = "-"
	// OperatorMultiply is the function/operator keyword *
	OperatorMultiply = "*"
	// OperatorDivide is the function/operator keyword /
	OperatorDivide = "/"

	// FuncTypeVersion is the function/operator keyword t_version
	FuncTypeVersion = "t_version"
	// FuncTypeTime is the function/operator keyword t_time
	FuncTypeTime = "t_time"
	// FuncTypeDefaultTime is the function/operator keyword td_time
	FuncTypeDefaultTime = "td_time"
	// FuncTypeDefaultDate is the function/operator keyword td_date
	FuncTypeDefaultDate = "td_date"
)
View Source
const (
	// ModeAnd is the mode add for function AndOr
	ModeAnd uint8 = iota + 1
	// ModeOr is the mode or for function AndOr
	ModeOr

	// ModeGreaterThan is the mod > for function Compare
	ModeGreaterThan
	// ModeLessThan is the mod < for function Compare
	ModeLessThan
	// ModeGreaterThanOrEqualTo is the mod >= for function Compare
	ModeGreaterThanOrEqualTo
	// ModeLessThanOrEqualTo is the mod <= for function Compare
	ModeLessThanOrEqualTo

	// ModeAdd is the mode + for function SuccessiveBinaryOperator
	ModeAdd
	// ModeMultiply is the mode * for function SuccessiveBinaryOperator
	ModeMultiply
	// ModeSubtract is the mode - for function BinaryOperator
	ModeSubtract
	// ModeDivide is the mode / for function BinaryOperator
	ModeDivide
)
View Source
const (
	// DefaultTimeFormat is the default time format
	DefaultTimeFormat = "2006-01-02 15:04:05"
	// DefaultDateFormat is the default date format
	DefaultDateFormat = "2006-01-02"
)

Variables

View Source
var (
	// ErrNotFound means the function is not implemented
	ErrNotFound = errors.New("function not implemented")
	// ErrParamsInvalid means the passed params are invalid
	ErrParamsInvalid = errors.New("params are invalid")
	// ErrFunctionExists means the function exists when registering
	ErrFunctionExists = errors.New("function exists")
	// ErrIllegalFormat means the data format is not legal
	ErrIllegalFormat = errors.New("illegal data format")
)

Functions

func Between

func Between(params ...interface{}) (interface{}, error)

Between returns whether first param is in the range between second and third param. The input params must be comparable

func In

func In(params ...interface{}) (interface{}, error)

In returns whether first param is in the second param(must be array type). The length of params must be 2

func Modulo

func Modulo(params ...interface{}) (interface{}, error)

Modulo implements mod operator in go

func MustRegist

func MustRegist(name string, fn Func)

MustRegist is same as Regist but may overide if function with name existed

func MustRegistFuncer

func MustRegistFuncer(name string, fn Funcer)

MustRegistFuncer is same as RegistFuncer but may overide if function with name existed

func Not

func Not(params ...interface{}) (interface{}, error)

Not implements logic operator "not"

func NotEqual

func NotEqual(params ...interface{}) (res interface{}, err error)

NotEqual returns whether the input params are not equal with each other, array type is supported too

func Overlap

func Overlap(params ...interface{}) (interface{}, error)

Overlap returns whether two arrays have element(s) in common. The length of params must be 2 and type must be array.

func Regist

func Regist(name string, fn Func) error

Regist regists fn with type Func with name of name

func RegistFuncer

func RegistFuncer(name string, fn Funcer) error

RegistFuncer regists fn with type Funcer with name of name

func Registered

func Registered() []string

Registered returns all registered functions or operators

func Uniform

func Uniform(params ...interface{}) []interface{}

Uniform converts any number-like element to type of float64 as much as possible

Types

type AndOr

type AndOr struct {
	Mode uint8
}

AndOr implements logic operator "and" "or"

func (AndOr) Eval

func (f AndOr) Eval(params ...interface{}) (interface{}, error)

Eval implements the interface Funcer

type BinaryOperator

type BinaryOperator struct {
	Mode uint8
}

BinaryOperator implements minus and divide

func (BinaryOperator) Eval

func (f BinaryOperator) Eval(params ...interface{}) (interface{}, error)

Eval implements the interface Funcer

type Compare

type Compare struct {
	// support mode: > < >= <=
	Mode uint8
}

Compare compare the two inputs with the given mode.

func (Compare) Eval

func (f Compare) Eval(params ...interface{}) (interface{}, error)

Eval implements the interface Funcer

type Equal

type Equal struct{}

Equal returns whether the input params are equal to each other, array type is supported too

func (Equal) Eval

func (f Equal) Eval(params ...interface{}) (res interface{}, err error)

Eval implements the interface Funcer

type Func

type Func func(params ...interface{}) (interface{}, error)

Func is a handy function type

func Get

func Get(name string) (Func, error)

Get get a registered function by name

type Funcer

type Funcer interface {
	Eval(params ...interface{}) (interface{}, error)
}

Funcer is the function interface which will be used to evaluate expressionn

type SuccessiveBinaryOperator

type SuccessiveBinaryOperator struct {
	Mode uint8
}

SuccessiveBinaryOperator implements successive plus or multiply

func (SuccessiveBinaryOperator) Eval

func (f SuccessiveBinaryOperator) Eval(params ...interface{}) (interface{}, error)

Eval implements the interface Funcer

type TypeTime

type TypeTime struct {
	Format string
}

TypeTime converts given string to the time.Time on the format of Format

func (TypeTime) Eval

func (f TypeTime) Eval(params ...interface{}) (res interface{}, err error)

Eval implements the interface Funcer

type TypeVersion

type TypeVersion struct{}

TypeVersion converts version string to a comparable number

func (TypeVersion) Eval

func (f TypeVersion) Eval(params ...interface{}) (interface{}, error)

Eval implements the interface Funcer

Jump to

Keyboard shortcuts

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