Documentation ¶
Overview ¶
Package function provides basic functions which implement Funcer interface
Index ¶
- Constants
- Variables
- func Between(params ...interface{}) (interface{}, error)
- func In(params ...interface{}) (interface{}, error)
- func Modulo(params ...interface{}) (interface{}, error)
- func MustRegist(name string, fn Func)
- func MustRegistFuncer(name string, fn Funcer)
- func Not(params ...interface{}) (interface{}, error)
- func NotEqual(params ...interface{}) (res interface{}, err error)
- func Overlap(params ...interface{}) (interface{}, error)
- func Regist(name string, fn Func) error
- func RegistFuncer(name string, fn Funcer) error
- func Registered() []string
- func Uniform(params ...interface{}) []interface{}
- type AndOr
- type BinaryOperator
- type Compare
- type Equal
- type Func
- type Funcer
- type SuccessiveBinaryOperator
- type TypeTime
- type TypeVersion
Constants ¶
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" )
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 )
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 ¶
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 ¶
MustRegist is same as Regist but may overide if function with name existed
func MustRegistFuncer ¶
MustRegistFuncer is same as RegistFuncer but may overide if function with name existed
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 RegistFuncer ¶
RegistFuncer regists fn with type Funcer with name of name
func Registered ¶
func Registered() []string
Registered returns all registered functions or operators
Types ¶
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.
type Equal ¶
type Equal struct{}
Equal returns whether the input params are equal to each other, array type is supported too
type Func ¶
type Func func(params ...interface{}) (interface{}, error)
Func is a handy function type
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
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