MCPcopy Create free account
hub / github.com/astercloud/aster / main

Function main

examples/workflow_steps/main.go:15–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func main() {
16 fmt.Println("=== Aster Workflow 所有步骤类型测试 ===")
17
18 ctx := context.Background()
19
20 // 1. FunctionStep
21 fmt.Println("1️⃣ FunctionStep")
22 funcStep := workflow.NewFunctionStep("func", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
23 return &workflow.StepOutput{
24 Content: "Function executed",
25 Metadata: make(map[string]any),
26 }, nil
27 })
28 fmt.Printf(" ✅ Created: %s (type: %s)\n\n", funcStep.Name(), funcStep.Type())
29
30 // 2. ConditionStep
31 fmt.Println("2️⃣ ConditionStep")
32 trueStep := workflow.NewFunctionStep("true", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
33 return &workflow.StepOutput{Content: "True branch", Metadata: make(map[string]any)}, nil
34 })
35 falseStep := workflow.NewFunctionStep("false", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
36 return &workflow.StepOutput{Content: "False branch", Metadata: make(map[string]any)}, nil
37 })
38 condStep := workflow.NewConditionStep("cond", func(input *workflow.StepInput) bool {
39 return true
40 }, trueStep, falseStep)
41 fmt.Printf(" ✅ Created: %s (type: %s)\n\n", condStep.Name(), condStep.Type())
42
43 // 3. LoopStep
44 fmt.Println("3️⃣ LoopStep")
45 loopBody := workflow.NewFunctionStep("body", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
46 return &workflow.StepOutput{Content: "Loop iteration", Metadata: make(map[string]any)}, nil
47 })
48 loopStep := workflow.NewLoopStep("loop", loopBody, 3)
49 fmt.Printf(" ✅ Created: %s (type: %s, max: 3 iterations)\n\n", loopStep.Name(), loopStep.Type())
50
51 // 4. ParallelStep
52 fmt.Println("4️⃣ ParallelStep")
53 task1 := workflow.NewFunctionStep("task1", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
54 time.Sleep(10 * time.Millisecond)
55 return &workflow.StepOutput{Content: "Task 1", Metadata: make(map[string]any)}, nil
56 })
57 task2 := workflow.NewFunctionStep("task2", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
58 time.Sleep(10 * time.Millisecond)
59 return &workflow.StepOutput{Content: "Task 2", Metadata: make(map[string]any)}, nil
60 })
61 parallelStep := workflow.NewParallelStep("parallel", task1, task2)
62 fmt.Printf(" ✅ Created: %s (type: %s, tasks: 2)\n\n", parallelStep.Name(), parallelStep.Type())
63
64 // 5. RouterStep
65 fmt.Println("5️⃣ RouterStep")
66 routeA := workflow.NewFunctionStep("route_a", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
67 return &workflow.StepOutput{Content: "Route A", Metadata: make(map[string]any)}, nil
68 })
69 routeB := workflow.NewFunctionStep("route_b", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
70 return &workflow.StepOutput{Content: "Route B", Metadata: make(map[string]any)}, nil
71 })
72 routerStep := workflow.NewRouterStep("router", func(input *workflow.StepInput) string {

Callers

nothing calls this directly

Calls 15

NameMethod · 0.95
TypeMethod · 0.95
NameMethod · 0.95
TypeMethod · 0.95
NameMethod · 0.95
TypeMethod · 0.95
NameMethod · 0.95
TypeMethod · 0.95
NameMethod · 0.95
TypeMethod · 0.95
NameMethod · 0.95
TypeMethod · 0.95

Tested by

no test coverage detected