package component import ( "fmt" ) type BaseComponent struct { typeName string name string runParams map[string]any } func NewBaseComponent(typeName string, name string, runParams map[string]any) *BaseComponent { return &BaseComponent{ typeName: typeName, name: name, runParams: runParams, } } func (c *BaseComponent) GetType() string { return c.typeName } func (c *BaseComponent) GetName() string { return c.name } type RunFunc func(globalRunParams *GlobalRunParams, dynamicParams map[string]any) (any, error) func (c *BaseComponent) OnRun(globalRunParams *GlobalRunParams, dynamicParams map[string]any, runFunc RunFunc) (any, error) { if globalRunParams == nil { globalRunParams = new(GlobalRunParams) } fmt.Println("----------" + c.typeName + "::" + c.name + "开始运行----------") if dynamicParams == nil { dynamicParams = make(map[string]any) } for key, params := range c.runParams { _, ok := dynamicParams[key] if !ok { dynamicParams[key] = params } } result, err := runFunc(globalRunParams, dynamicParams) if err != nil { return nil, err } if result != nil { globalRunParams.SetLastResult(result) } fmt.Println("----------" + c.typeName + "类型的" + c.name + "结束运行----------") return result, nil }