kis-flow/kis/action.go
2024-01-23 16:24:16 +08:00

59 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package kis
// Action KisFlow执行流程Actions
type Action struct {
// DataReuse 是否复用上层Function数据
DataReuse bool
// 默认Next()为如果本层Function计算结果为0条数据之后Function将不会继续执行
// ForceEntryNext 为忽略上述默认规则没有数据强制进入下一层Function
ForceEntryNext bool
// JumpFunc 跳转到指定Function继续执行
JumpFunc string
// Abort 终止Flow的执行
Abort bool
}
// ActionFunc KisFlow Functional Option 类型
type ActionFunc func(ops *Action)
// LoadActions 加载Actions依次执行ActionFunc操作函数
func LoadActions(acts []ActionFunc) Action {
action := Action{}
if acts == nil {
return action
}
for _, act := range acts {
act(&action)
}
return action
}
// ActionDataReuse Next复用上层Function数据Option
func ActionDataReuse(act *Action) {
act.DataReuse = true
}
// ActionForceEntryNext 强制进入下一层
func ActionForceEntryNext(act *Action) {
act.ForceEntryNext = true
}
// ActionJumpFunc 会返回一个ActionFunc函数并且会将funcName赋值给Action.JumpFunc
// (注意容易出现Flow循环调用导致死循环)
func ActionJumpFunc(funcName string) ActionFunc {
return func(act *Action) {
act.JumpFunc = funcName
}
}
// ActionAbort 终止Flow的执行
func ActionAbort(action *Action) {
action.Abort = true
}