kis-flow/kis/action.go

61 lines
1.7 KiB
Go
Raw Normal View History

2024-01-23 16:24:16 +08:00
package kis
2024-04-15 17:50:02 +08:00
// Action defines the actions for KisFlow execution.
2024-01-23 16:24:16 +08:00
type Action struct {
2024-04-15 17:50:02 +08:00
// DataReuse indicates whether to reuse data from the upper Function.
2024-01-23 16:24:16 +08:00
DataReuse bool
2024-04-15 17:50:02 +08:00
// ForceEntryNext overrides the default rule, where if the current Function's calculation result is 0 data entries,
// subsequent Functions will not continue execution.
// With ForceEntryNext set to true, the next Function will be entered regardless of the data.
2024-01-23 16:24:16 +08:00
ForceEntryNext bool
2024-04-15 17:50:02 +08:00
// JumpFunc specifies the Function to jump to for continued execution.
// (Note: This can easily lead to Flow loop calls, causing an infinite loop.)
2024-01-23 16:24:16 +08:00
JumpFunc string
2024-04-15 17:50:02 +08:00
// Abort terminates the execution of the Flow.
2024-01-23 16:24:16 +08:00
Abort bool
}
2024-04-15 17:50:02 +08:00
// ActionFunc is the type for KisFlow Functional Option.
2024-01-23 16:24:16 +08:00
type ActionFunc func(ops *Action)
2024-04-15 17:50:02 +08:00
// LoadActions loads Actions and sequentially executes the ActionFunc operations.
2024-01-23 16:24:16 +08:00
func LoadActions(acts []ActionFunc) Action {
action := Action{}
if acts == nil {
return action
}
for _, act := range acts {
act(&action)
}
return action
}
2024-04-15 17:50:02 +08:00
// ActionDataReuse sets the option for reusing data from the upper Function.
2024-01-23 16:24:16 +08:00
func ActionDataReuse(act *Action) {
act.DataReuse = true
}
2024-04-15 17:50:02 +08:00
// ActionForceEntryNext sets the option to forcefully enter the next layer.
2024-01-23 16:24:16 +08:00
func ActionForceEntryNext(act *Action) {
act.ForceEntryNext = true
}
2024-04-15 17:50:02 +08:00
// ActionJumpFunc returns an ActionFunc function and sets the funcName to Action.JumpFunc.
// (Note: This can easily lead to Flow loop calls, causing an infinite loop.)
2024-01-23 16:24:16 +08:00
func ActionJumpFunc(funcName string) ActionFunc {
return func(act *Action) {
act.JumpFunc = funcName
}
}
2024-04-15 17:50:02 +08:00
// ActionAbort terminates the execution of the Flow.
2024-01-23 16:24:16 +08:00
func ActionAbort(action *Action) {
action.Abort = true
}