pattern

package module
v0.0.0-...-51154d2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 14 Imported by: 1

README

pattern

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidReturnValType = errors.New("invalid return value type")
)

Functions

func Eval

func Eval(expression string, data interface{}) (string, error)

Eval 对 data 应用表达式

func Match

func Match(expression string, data interface{}) (bool, error)

Match 检查 data 是否匹配表达式

func StringEval

func StringEval(expression string, data string) (string, error)

StringEval 对 data 应用表达式

func StringMatch

func StringMatch(expression string, data string) (bool, error)

StringMatch 检查 data 是否匹配表达式

Types

type Data

type Data struct {
	Helpers
	Data string
}

Data 封装了助手函数和匹配数据的结构体

func (Data) CtxJSON

func (d Data) CtxJSON(path string) string

CtxJSON return string from json

func (Data) CtxJSONArray

func (d Data) CtxJSONArray(path string) []gjson.Result

CtxJSONArray return array from json

func (Data) CtxJSONBool

func (d Data) CtxJSONBool(path string) bool

CtxJSONBool return bool from json

func (Data) CtxJSONBoolArray

func (d Data) CtxJSONBoolArray(path string) []bool

CtxJSONBoolArray return bool array from json

func (Data) CtxJSONFloat

func (d Data) CtxJSONFloat(path string) float64

CtxJSONFloat return float64 from json

func (Data) CtxJSONFloatArray

func (d Data) CtxJSONFloatArray(path string) []float64

CtxJSONFloatArray return float64 array from json

func (Data) CtxJSONInt

func (d Data) CtxJSONInt(path string) int64

CtxJSONInt return int from json

func (Data) CtxJSONIntArray

func (d Data) CtxJSONIntArray(path string) []int64

CtxJSONIntArray return int array from json

func (Data) CtxJSONStrArray

func (d Data) CtxJSONStrArray(path string) []string

CtxJSONStrArray get string array from json

func (Data) DOM

func (d Data) DOM(selector string, data ...string) []string

DOM 从 HTML DOM 对象中查询所有匹配 selector 的元素

func (Data) DOMOne

func (d Data) DOMOne(selector string, index int, data ...string) string

DOMOne 从 HTML DOM 对象中查询第 index 个匹配 selector 的元素内容

func (Data) JQ

func (d Data) JQ(expression string, data ...string) string

JQ 执行 JQuery 表达式查询 json 字符串,如果表达式错误,则返回空字符串

func (Data) JQE

func (d Data) JQE(expression string, data ...string) string

JQE 执行 JQuery 表达式查询 json 字符串,如果表达式错误,则返回 `<ERORR> 错误详情`

type Evaluator

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

Evaluator 用于计算 data 在应用 expression 后的结果

func NewEvaluator

func NewEvaluator(expression string, dataType interface{}) (*Evaluator, error)

NewEvaluator 创建一个新的 Evaluator

func (*Evaluator) Eval

func (eval *Evaluator) Eval(data interface{}) (string, error)

Eval 对 data 应用 expression 表达式,返回评估后的结果

type Helpers

type Helpers struct{}

Helpers 用于规则引擎的助手函数

func (Helpers) Between

func (Helpers) Between(val int, min int, max int) bool

Between 判断 数字 Val 是否在 [min,max] 范围内

func (Helpers) CutOff

func (Helpers) CutOff(maxLen int, val string) string

CutOff 字符串截断

func (Helpers) CutoffLine

func (Helpers) CutoffLine(maxLine int, val string) string

CutoffLine 字符串截取指定行数

func (Helpers) DOMQuery

func (helper Helpers) DOMQuery(selector string, htmlContent string) []string

DOMQuery 从 HTML DOM 对象中查询所有匹配 selector 的元素

func (Helpers) DOMQueryOne

func (helper Helpers) DOMQueryOne(selector string, index int, htmlContent string) string

DOMQueryOne 从 HTML DOM 对象中查询第 index 个匹配 selector 的元素内容

func (Helpers) DailyTimeBetween

func (Helpers) DailyTimeBetween(startTime, endTime string) bool

DailyTimeBetween 判断当前时间(格式 15:04)是否在 startTime 和 endTime 之间

func (Helpers) Empty

func (Helpers) Empty(str string) bool

Empty 检查字符串是否为空 `空白`, `0`,`任意大小写的 false` 会被认为是 false,其它情况为 true

func (Helpers) EqualFold

func (Helpers) EqualFold(s1, s2 string) bool

EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.

func (Helpers) FilterEmptyLines

func (Helpers) FilterEmptyLines(content string) string

FilterEmptyLines 从字符串中移除空行

func (Helpers) Float

func (Helpers) Float(numStr string) float64

Float 字符串转浮点数

func (Helpers) Int

func (Helpers) Int(numStr string) int

Int 字符串转整数

func (Helpers) JQuery

func (helper Helpers) JQuery(data string, expression string, suppressError bool) string

JQuery 使用 JQ 表达式提取 json 字符串中的值

func (Helpers) JSON

func (helper Helpers) JSON(content string, path string) string

JSON return string content from json

func (Helpers) JSONArray

func (helper Helpers) JSONArray(content string, path string) []gjson.Result

JSONArray return array elements from path

func (Helpers) JSONBool

func (helper Helpers) JSONBool(content string, path string) bool

JSONBool return bool content from json

func (Helpers) JSONBoolArray

func (helper Helpers) JSONBoolArray(content string, path string) []bool

JSONBoolArray return bool array from json

func (Helpers) JSONEncode

func (helper Helpers) JSONEncode(data interface{}) string

func (Helpers) JSONFloat

func (helper Helpers) JSONFloat(content string, path string) float64

JSONFloat return float64 content from json

func (Helpers) JSONFloatArray

func (helper Helpers) JSONFloatArray(content string, path string) []float64

JSONFloatArray return float64 array from json

func (Helpers) JSONInt

func (helper Helpers) JSONInt(content string, path string) int64

JSONInt return int content from json

func (Helpers) JSONIntArray

func (helper Helpers) JSONIntArray(content string, path string) []int64

JSONIntArray return int64 array from json

func (Helpers) JSONStrArray

func (helper Helpers) JSONStrArray(content string, path string) []string

JSONStrArray return string array from json

func (Helpers) Join

func (Helpers) Join(elements interface{}, sep string) string

Join 字符串数组拼接

func (Helpers) Lower

func (Helpers) Lower(val string) string

Lower returns a copy of the string s with all Unicode letters mapped to their lower case.

func (Helpers) Mask

func (Helpers) Mask(left int, content string) string

stringMask create a mask for string

func (Helpers) Now

func (Helpers) Now() time.Time

Now return current time

func (Helpers) NumberBeauty

func (Helpers) NumberBeauty(number interface{}) string

NumberBeauty 字符串数字格式化

func (Helpers) ParseTime

func (Helpers) ParseTime(layout string, value string) time.Time

ParseTime parse a string to time.Time layout: Mon Jan 2 15:04:05 -0700 MST 2006

func (Helpers) Repeat

func (Helpers) Repeat(count int, s string) string

Repeat 字符串重复 count 次

func (Helpers) Split

func (Helpers) Split(sep string, content string) []string

Split 字符串分割

func (Helpers) String

func (helper Helpers) String(data interface{}) string

String convert any data to string

func (Helpers) TrimPrefix

func (Helpers) TrimPrefix(s, prefix string) string

TrimPrefix 字符串去除前缀

func (Helpers) TrimSpace

func (Helpers) TrimSpace(s string) string

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func (Helpers) TrimSuffix

func (Helpers) TrimSuffix(s, suffix string) string

TrimSuffix 字符串去除后缀

func (Helpers) Upper

func (Helpers) Upper(val string) string

Upper returns a copy of the string s with all Unicode letters mapped to their upper case.

type Matcher

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

Matcher 用于检查 data 是否匹配表达式

func NewMatcher

func NewMatcher(expression string, dataType interface{}) (*Matcher, error)

NewMatcher 创建一个新的 Matcher

func (*Matcher) Match

func (matcher *Matcher) Match(data interface{}) (bool, error)

Match 执行匹配,检查 data 是否能够通过 expression 的评估

Jump to

Keyboard shortcuts

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