-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteps.go
More file actions
67 lines (60 loc) · 1.88 KB
/
steps.go
File metadata and controls
67 lines (60 loc) · 1.88 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package conditional
import (
"fmt"
"github.com/sicko7947/gorkflow"
)
func NewSetupStep() *gorkflow.Step[ConditionalInput, DoubleInput] {
return gorkflow.NewStep(
"setup",
"Setup Conditional Flags",
func(ctx *gorkflow.StepContext, input ConditionalInput) (DoubleInput, error) {
// Store flags in state for condition evaluation
ctx.State.Set("enable_doubling", input.EnableDoubling)
ctx.State.Set("enable_formatting", input.EnableFormatting)
ctx.Logger.Info().
Bool("enable_doubling", input.EnableDoubling).
Bool("enable_formatting", input.EnableFormatting).
Msg("Conditional flags set in state")
// Pass the value to the next step
return DoubleInput{Value: input.Value}, nil
},
)
}
func NewDoubleStep() *gorkflow.Step[DoubleInput, DoubleOutput] {
return gorkflow.NewStep(
"double",
"Double the Value",
func(ctx *gorkflow.StepContext, input DoubleInput) (DoubleOutput, error) {
doubled := input.Value * 2
ctx.Logger.Info().
Int("original", input.Value).
Int("doubled", doubled).
Msg("Doubling value")
return DoubleOutput{
Value: doubled,
Doubled: true,
Message: fmt.Sprintf("Doubled %d to %d", input.Value, doubled),
}, nil
},
)
}
func NewConditionalFormatStep() *gorkflow.Step[ConditionalFormatInput, ConditionalFormatOutput] {
return gorkflow.NewStep(
"conditional_format",
"Format Result Conditionally",
func(ctx *gorkflow.StepContext, input ConditionalFormatInput) (ConditionalFormatOutput, error) {
formatted := fmt.Sprintf("Final value: %d (doubled: %v)", input.Value, input.Doubled)
if input.Message != "" {
formatted = fmt.Sprintf("%s | %s", formatted, input.Message)
}
ctx.Logger.Info().
Str("formatted", formatted).
Msg("Formatting conditional result")
return ConditionalFormatOutput{
Value: input.Value,
Formatted: formatted,
Doubled: input.Doubled,
}, nil
},
)
}