-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage.go
35 lines (29 loc) · 1.1 KB
/
stage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package pipeliner
type ActionResult[T any] struct {
StageOfOrigin *Stage[T]
Success bool
Continue bool
Message string
Data any
}
func Error[T any](message string, data any) ActionResult[T] {
return ActionResult[T]{Success: false, Continue: false, Message: message, Data: data}
}
func Success[T any](message string, data any) ActionResult[T] {
return ActionResult[T]{Success: true, Continue: true, Message: message, Data: data}
}
func Done[T any](message string, data any) ActionResult[T] {
return ActionResult[T]{Success: true, Continue: false, Message: message, Data: data}
}
type Stage[T any] struct {
Name string // stores the name of the stage
PatternMatcher func(T) (bool, error) // stores the pattern matcher to be used by the stage
Action func(T) ActionResult[T] // stores the action to be performed by the stage
}
func NewStage[T any](name string, pattern_matcher func(T) (bool, error), action func(T) ActionResult[T]) Stage[T] {
return Stage[T]{
Name: name,
PatternMatcher: pattern_matcher,
Action: action,
}
}