ChainRouter 创建链式路由器 根据条件选择多个步骤顺序执行
(name string, selector func(*StepInput) []string, routes map[string]Step)
| 417 | // ChainRouter 创建链式路由器 |
| 418 | // 根据条件选择多个步骤顺序执行 |
| 419 | func ChainRouter(name string, selector func(*StepInput) []string, routes map[string]Step) *Router { |
| 420 | // 从 map 构建 choices |
| 421 | choices := make([]Step, 0, len(routes)) |
| 422 | for _, step := range routes { |
| 423 | choices = append(choices, step) |
| 424 | } |
| 425 | |
| 426 | // 选择器函数:根据条件返回多个步骤 |
| 427 | selectorFunc := func(input *StepInput) []Step { |
| 428 | stepNames := selector(input) |
| 429 | steps := make([]Step, 0, len(stepNames)) |
| 430 | for _, name := range stepNames { |
| 431 | if step, exists := routes[name]; exists { |
| 432 | steps = append(steps, step) |
| 433 | } |
| 434 | } |
| 435 | return steps |
| 436 | } |
| 437 | |
| 438 | return NewRouter(name, selectorFunc, choices) |
| 439 | } |
| 440 | |
| 441 | // DynamicRouter 创建动态路由器 |
| 442 | // 完全自定义的步骤选择逻辑 |
no test coverage detected