===== 简化的 Router 构造函数 ===== SimpleRouter 创建简单的条件路由器 根据条件选择单个步骤执行
(name string, condition func(*StepInput) string, routes map[string]Step)
| 396 | // SimpleRouter 创建简单的条件路由器 |
| 397 | // 根据条件选择单个步骤执行 |
| 398 | func SimpleRouter(name string, condition func(*StepInput) string, routes map[string]Step) *Router { |
| 399 | // 从 map 构建 choices |
| 400 | choices := make([]Step, 0, len(routes)) |
| 401 | for _, step := range routes { |
| 402 | choices = append(choices, step) |
| 403 | } |
| 404 | |
| 405 | // 选择器函数:根据条件返回单个步骤 |
| 406 | selector := func(input *StepInput) []Step { |
| 407 | routeName := condition(input) |
| 408 | if step, exists := routes[routeName]; exists { |
| 409 | return []Step{step} |
| 410 | } |
| 411 | return []Step{} |
| 412 | } |
| 413 | |
| 414 | return NewRouter(name, selector, choices) |
| 415 | } |
| 416 | |
| 417 | // ChainRouter 创建链式路由器 |
| 418 | // 根据条件选择多个步骤顺序执行 |
no test coverage detected