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

Function SimpleRouter

pkg/workflow/router.go:398–415  ·  view source on GitHub ↗

===== 简化的 Router 构造函数 ===== SimpleRouter 创建简单的条件路由器 根据条件选择单个步骤执行

(name string, condition func(*StepInput) string, routes map[string]Step)

Source from the content-addressed store, hash-verified

396// SimpleRouter 创建简单的条件路由器
397// 根据条件选择单个步骤执行
398func 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// 根据条件选择多个步骤顺序执行

Callers 2

mainFunction · 0.92
testRouterFunction · 0.92

Calls 1

NewRouterFunction · 0.85

Tested by

no test coverage detected