added some helper function
@@ -66,14 +66,48 @@ func (m *Matcher) CompileMatchers() error {
func helperFunctions() (functions map[string]govaluate.ExpressionFunction) {
functions = make(map[string]govaluate.ExpressionFunction)
+ // strings
functions["len"] = func(args ...interface{}) (interface{}, error) {
length := len(args[0].(string))
return (float64)(length), nil
}
+ functions["toupper"] = func(args ...interface{}) (interface{}, error) {
+ return strings.ToUpper(args[0].(string)), nil
+ }
+ functions["tolower"] = func(args ...interface{}) (interface{}, error) {
+ return strings.ToLower(args[0].(string)), nil
+ }
+ functions["replace"] = func(args ...interface{}) (interface{}, error) {
+ return strings.Replace(args[0].(string), args[1].(string), args[2].(string), -1), nil
+ }
+ functions["trim"] = func(args ...interface{}) (interface{}, error) {
+ return strings.Trim(args[0].(string), args[2].(string)), nil
+ }
+ functions["trimleft"] = func(args ...interface{}) (interface{}, error) {
+ return strings.TrimLeft(args[0].(string), args[1].(string)), nil
+ }
+ functions["trimright"] = func(args ...interface{}) (interface{}, error) {
+ return strings.TrimRight(args[0].(string), args[1].(string)), nil
+ }
+ functions["trimspace"] = func(args ...interface{}) (interface{}, error) {
+ return strings.TrimSpace(args[0].(string)), nil
+ }
+ functions["trimprefix"] = func(args ...interface{}) (interface{}, error) {
+ return strings.TrimPrefix(args[0].(string), args[1].(string)), nil
+ }
+ functions["trimsuffix"] = func(args ...interface{}) (interface{}, error) {
+ return strings.TrimSuffix(args[0].(string), args[1].(string)), nil
+ }
+ // encoding
functions["base64"] = func(args ...interface{}) (interface{}, error) {
sEnc := base64.StdEncoding.EncodeToString([]byte(args[0].(string)))
return sEnc, nil
}
+ functions["base64_decode"] = func(args ...interface{}) (interface{}, error) {
+ sEnc := base64.StdEncoding.EncodeToString([]byte(args[0].(string)))
+ return sEnc, nil
+ }
+ // hashing
functions["md5"] = func(args ...interface{}) (interface{}, error) {
hash := md5.Sum([]byte(args[0].(string)))
return hex.EncodeToString(hash[:]), nil
@@ -81,6 +115,7 @@ func helperFunctions() (functions map[string]govaluate.ExpressionFunction) {
functions["sha256"] = func(args ...interface{}) (interface{}, error) {
return sha256.Sum256([]byte(args[0].(string))), nil
}
+ // search
functions["contains"] = func(args ...interface{}) (interface{}, error) {
return strings.Contains(args[0].(string), args[1].(string)), nil
}
