helper

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Computes = map[string]ComputeFunc{
	"=": func(left interface{}, right interface{}) bool {
		return left == right
	},
	">": func(left interface{}, right interface{}) bool {
		return any.Of(left).CFloat64() == any.Of(right).CFloat64()
	},
	">=": func(left interface{}, right interface{}) bool {
		return any.Of(left).CFloat64() >= any.Of(right).CFloat64()
	},
	"<": func(left interface{}, right interface{}) bool {
		return any.Of(left).CFloat64() < any.Of(right).CFloat64()
	},
	"<=": func(left interface{}, right interface{}) bool {
		return any.Of(left).CFloat64() <= any.Of(right).CFloat64()
	},
	"!=": func(left interface{}, right interface{}) bool {
		return left != right
	},
	"hasprefix": func(left interface{}, right interface{}) bool {
		return strings.HasPrefix(fmt.Sprintf("%v", left), fmt.Sprintf("%v", right))
	},
	"hassuffix": func(left interface{}, right interface{}) bool {
		return strings.HasSuffix(fmt.Sprintf("%v", left), fmt.Sprintf("%v", right))
	},
	"contains": func(left interface{}, right interface{}) bool {
		return strings.Contains(fmt.Sprintf("%v", left), fmt.Sprintf("%v", right))
	},
	"match": func(left interface{}, right interface{}) bool {
		re := regexp.MustCompile(fmt.Sprintf("%v", right))
		return re.Match([]byte(fmt.Sprintf("%v", left)))
	},
	"is": func(left interface{}, right interface{}) bool {
		if is, ok := right.(string); ok {
			is = strings.ToLower(is)
			if is == "null" {
				return left == nil
			} else if is == "notnull" {
				return left != nil
			}
		}
		return false
	},
}

Computes 可用计算式

Functions

func ArrayColumn

func ArrayColumn(records []map[string]interface{}, name string) []interface{}

ArrayColumn 返回多条数据记录,指定字段数值。

func ArrayKeep

func ArrayKeep(records []map[string]interface{}, keeps []string) []map[string]interface{}

ArrayKeep 仅保留指定键名的数据

func ArrayMapSet

func ArrayMapSet(records []map[string]interface{}, key string, value interface{}) []map[string]interface{}

ArrayMapSet []map[string]interface{} 设定数值

func ArrayMapSetMapStr

func ArrayMapSetMapStr(records []maps.MapStr, key string, value interface{}) []maps.MapStr

ArrayMapSetMapStr []map[string]interface{} 设定数值

func ArrayPluck

func ArrayPluck(columns []string, pluck map[string]interface{}) []map[string]interface{}

ArrayPluck 将多个数据记录集合,合并为一个数据记录集合

	columns: ["城市", "行业", "计费"]
	pluck: {
		"行业":{"key":"city", "value":"数量", "items":[{"city":"北京", "数量":32},{"city":"上海", "数量":20}]},
		"计费":{"key":"city", "value":"计费种类", "items":[{"city":"北京", "计费种类":6},{"city":"西安", "计费种类":3}]},
 }

return: [

{"城市":"北京", "行业":32, "计费":6},
{"城市":"上海", "行业":20, "计费":null},
{"城市":"西安", "行业":null, "计费":6}

]

func ArraySplit

func ArraySplit(records []map[string]interface{}) ([]string, [][]interface{})

ArraySplit 将多条数记录集合,分解为一个 columns:[]string 和 values: [][]interface{}

func ArrayStringUnique

func ArrayStringUnique(columns []string) []string

ArrayStringUnique 数组排重

func ArrayTree

func ArrayTree(records []map[string]interface{}, setting map[string]interface{}) []map[string]interface{}

ArrayTree []map[string]interface{} 转树形结构

func ArrayUnique

func ArrayUnique(columns []interface{}) []interface{}

ArrayUnique 数组排重

func CaptchaMake

func CaptchaMake(option CaptchaOption) (string, string)

CaptchaMake 制作验证码

func CaptchaValidate

func CaptchaValidate(id string, code string) bool

CaptchaValidate 校验验证码

func Case

func Case(params ...CaseParam) interface{}

Case 条件判断

func For

func For(from int, to int, p Process)

For 过程控制

func IF

func IF(param CaseParam, paramElse ...CaseParam) interface{}

IF 条件判断

func MapDel

func MapDel(record map[string]interface{}, key string) map[string]interface{}

MapDel xiang.helper.MapDel 删除数值并返回新映射表

func MapGet

func MapGet(record map[string]interface{}, key string) interface{}

MapGet xiang.helper.MapGet 返回映射表给定键的值

func MapKeys

func MapKeys(record map[string]interface{}) []string

MapKeys 返回映射表的键

func MapMultiDel

func MapMultiDel(record map[string]interface{}, keys ...string) map[string]interface{}

MapMultiDel xiang.helper.MapMultiDel 删除数值并返回新映射表

func MapSet

func MapSet(record map[string]interface{}, key string, value interface{}) map[string]interface{}

MapSet xiang.helper.MapSet 设定数值并返回新映射表

func MapValues

func MapValues(record map[string]interface{}) []interface{}

MapValues 返回映射表的数值

func PasswordValidate

func PasswordValidate(password string, passwordHash string) bool

PasswordValidate 校验密码

func ProcessArrayColumn

func ProcessArrayColumn(process *process.Process) interface{}

ProcessArrayColumn xiang.helper.ArrayColumn 返回多条数据记录,指定字段数值。

func ProcessArrayGet

func ProcessArrayGet(process *process.Process) interface{}

ProcessArrayGet xiang.helper.ArrayGet 返回指定索引数据

func ProcessArrayIndexes

func ProcessArrayIndexes(process *process.Process) interface{}

ProcessArrayIndexes xiang.helper.ArrayIndexes 返回数组索引。

func ProcessArrayKeep

func ProcessArrayKeep(process *process.Process) interface{}

ProcessArrayKeep xiang.helper.ArrayKeep 仅保留指定键名的数据

func ProcessArrayMapSet

func ProcessArrayMapSet(process *process.Process) interface{}

ProcessArrayMapSet xiang.helper.ArrayMapSet 数组映射设定数值

func ProcessArrayPluck

func ProcessArrayPluck(process *process.Process) interface{}

ProcessArrayPluck xiang.helper.ArrayPluck 将多个数据记录集合,合并为一个数据记录集合

func ProcessArraySplit

func ProcessArraySplit(process *process.Process) interface{}

ProcessArraySplit xiang.helper.ArraySplit 将多条数记录集合,分解为一个 columns:[]string 和 values: [][]interface{}

func ProcessArrayTree

func ProcessArrayTree(process *process.Process) interface{}

ProcessArrayTree xiang.helper.ArrayTree 转换为属性结构

func ProcessArrayUnique

func ProcessArrayUnique(process *process.Process) interface{}

ProcessArrayUnique xiang.helper.ArrayUnique 数组排重

func ProcessCaptcha

func ProcessCaptcha(process *process.Process) interface{}

ProcessCaptcha xiang.helper.Captcha 校验图形/音频验证码

func ProcessCaptchaValidate

func ProcessCaptchaValidate(process *process.Process) interface{}

ProcessCaptchaValidate xiang.helper.CaptchaValidate 校验图形/音频验证码

func ProcessCase

func ProcessCase(process *process.Process) interface{}

ProcessCase xiang.helper.Case Case条件判断

func ProcessEach

func ProcessEach(process *process.Process) interface{}

ProcessEach xiang.helper.Each 循环过程控制

func ProcessEnvGet

func ProcessEnvGet(process *process.Process) interface{}

ProcessEnvGet xiang.helper.EnvGet 读取ENV

func ProcessEnvMultiGet

func ProcessEnvMultiGet(process *process.Process) interface{}

ProcessEnvMultiGet xiang.helper.MultiGet 读取ENV

func ProcessEnvMultiSet

func ProcessEnvMultiSet(process *process.Process) interface{}

ProcessEnvMultiSet xiang.helper.MultiSet 设置ENV

func ProcessEnvSet

func ProcessEnvSet(process *process.Process) interface{}

ProcessEnvSet xiang.helper.EnvSet 设置ENV

func ProcessFor

func ProcessFor(process *process.Process) interface{}

ProcessFor xiang.helper.For 循环过程控制

func ProcessHexToString added in v0.9.2

func ProcessHexToString(process *process.Process) interface{}

ProcessHexToString xiang.helper.HexToString

func ProcessIF

func ProcessIF(process *process.Process) interface{}

ProcessIF xiang.helper.IF IF条件判断

func ProcessJwtMake

func ProcessJwtMake(process *process.Process) interface{}

ProcessJwtMake xiang.helper.JwtMake 生成JWT

func ProcessJwtValidate

func ProcessJwtValidate(process *process.Process) interface{}

ProcessJwtValidate xiang.helper.JwtValidate 校验JWT

func ProcessMapDel

func ProcessMapDel(process *process.Process) interface{}

ProcessMapDel xiang.helper.MapDel 删除给定键, 返回映射表

func ProcessMapGet

func ProcessMapGet(process *process.Process) interface{}

ProcessMapGet xiang.helper.MapGet 返回映射表给定键的值

func ProcessMapKeys

func ProcessMapKeys(process *process.Process) interface{}

ProcessMapKeys xiang.helper.MapKeys 返回映射表的键

func ProcessMapMultiDel

func ProcessMapMultiDel(process *process.Process) interface{}

ProcessMapMultiDel xiang.helper.MapMultiDel 删除一组给定键, 返回映射表

func ProcessMapSet

func ProcessMapSet(process *process.Process) interface{}

ProcessMapSet xiang.helper.MapSet 设定键值,返回映射表给定键的值

func ProcessMapToArray

func ProcessMapToArray(process *process.Process) interface{}

ProcessMapToArray xiang.helper.MapToArray 映射转换为 KeyValue 数组

func ProcessMapValues

func ProcessMapValues(process *process.Process) interface{}

ProcessMapValues xiang.helper.MapValues 返回映射表的数值

func ProcessPasswordValidate

func ProcessPasswordValidate(process *process.Process) interface{}

ProcessPasswordValidate xiang.helper.PasswordValidate 校验密码

func ProcessPrint

func ProcessPrint(process *process.Process) interface{}

ProcessPrint xiang.helper.Print 打印语句

func ProcessReturn

func ProcessReturn(process *process.Process) interface{}

ProcessReturn xiang.helper.Return 返回数值

func ProcessSleep

func ProcessSleep(process *process.Process) interface{}

ProcessSleep xiang.flow.Sleep 等待

func ProcessStrConcat

func ProcessStrConcat(process *process.Process) interface{}

ProcessStrConcat xiang.helper.StrConcat 连接字符串

func ProcessThrow

func ProcessThrow(process *process.Process) interface{}

ProcessThrow xiang.helper.Throw 抛出异常

func Range

func Range(v interface{}, process Process)

Range 过程控制

func When

func When(conds []Condition) bool

When 多项条件判断

Types

type ArrayPluckValue

type ArrayPluckValue struct {
	Key   string                   `json:"key"`
	Value string                   `json:"value"`
	Items []map[string]interface{} `json:"items"`
}

ArrayPluckValue ArrayPluck 参数

func OfArrayPluckValue

func OfArrayPluckValue(any interface{}) ArrayPluckValue

OfArrayPluckValue Any 转 ArrayPluckValue

type ArrayTreeOption

type ArrayTreeOption struct {
	Key      string      `json:"id"`       // 主键名称, 默认为 id
	Empty    interface{} `json:"empty"`    // Top节点 parent 数值, 默认为 0
	Parent   string      `json:"parent"`   // 父节点字段名称, 默认为 parent
	Children string      `json:"children"` // 子节点字段名称, 默认为 children
}

ArrayTreeOption Array转树形结构参数表

func NewArrayTreeOption

func NewArrayTreeOption(option map[string]interface{}) ArrayTreeOption

NewArrayTreeOption 创建配置

func (ArrayTreeOption) Tree

func (opt ArrayTreeOption) Tree(records []map[string]interface{}) []map[string]interface{}

Tree Array 转换为 Tree

type CaptchaOption

type CaptchaOption struct {
	Type       string
	Height     int
	Width      int
	Length     int
	Lang       string
	Background string
}

CaptchaOption 验证码配置

func NewCaptchaOption

func NewCaptchaOption() CaptchaOption

NewCaptchaOption 创建验证码配置

type CaseParam

type CaseParam struct {
	When    []Condition   `json:"when"`
	Name    string        `json:"name"`
	Process string        `json:"process"`
	Args    []interface{} `json:"args"`
}

CaseParam 条件参数

func CaseParamOf

func CaseParamOf(v interface{}) CaseParam

CaseParamOf 读取参数

type ComputeFunc

type ComputeFunc func(interface{}, interface{}) bool

ComputeFunc 计算函数

type Condition

type Condition struct {
	Left    interface{} `json:"left"`
	Right   interface{} `json:"right"`
	Compute ComputeFunc `json:"-"`
	OP      string      `json:"op"`
	OR      bool        `json:"or"`
	Comment string      `json:"comment"`
}

Condition 判断条件

func ConditionOf

func ConditionOf(input map[string]interface{}) Condition

ConditionOf 从 map[string]interface{}

func (Condition) Exec

func (cond Condition) Exec() bool

Exec 执行条件判断

func (Condition) MarshalJSON

func (cond Condition) MarshalJSON() ([]byte, error)

MarshalJSON for json marshalJSON

func (Condition) ToMap

func (cond Condition) ToMap() map[string]interface{}

ToMap Condition 转换为 map[string]interface{}

func (*Condition) UnmarshalJSON

func (cond *Condition) UnmarshalJSON(data []byte) error

UnmarshalJSON for json marshalJSON

type JwtClaims

type JwtClaims struct {
	ID   int                    `json:"id"`
	SID  string                 `json:"sid"`
	Data map[string]interface{} `json:"data"`
	jwt.StandardClaims
}

JwtClaims 用户Token

func JwtValidate

func JwtValidate(tokenString string, secret ...[]byte) *JwtClaims

JwtValidate JWT 校验

type JwtToken

type JwtToken struct {
	Token     string `json:"token"`
	ExpiresAt int64  `json:"expires_at"`
}

JwtToken JWT令牌

func JwtMake

func JwtMake(id int, data map[string]interface{}, option map[string]interface{}, secret ...[]byte) JwtToken

JwtMake 生成 JWT option: {"subject":"<主题>", "audience": "<接收人>", "issuer":"<签发人>", "timeout": "<有效期,单位秒>", "sid":"<会话ID>"}

type Process

type Process struct {
	Process string        `json:"process"`
	Args    []interface{} `json:"args,omitempty"`
}

Process 处理器参数

func ProcessOf

func ProcessOf(v map[string]interface{}) Process

ProcessOf 转换映射表

Jump to

Keyboard shortcuts

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