===== 验证 ===== Validate 验证配置
()
| 147 | |
| 148 | // Validate 验证配置 |
| 149 | func (w *Workflow) Validate() error { |
| 150 | if w.Name == "" { |
| 151 | return errors.New("workflow name is required") |
| 152 | } |
| 153 | if len(w.Steps) == 0 { |
| 154 | return errors.New("workflow must have at least one step") |
| 155 | } |
| 156 | |
| 157 | stepNames := make(map[string]bool) |
| 158 | for _, step := range w.Steps { |
| 159 | if stepNames[step.Name()] { |
| 160 | return fmt.Errorf("duplicate step name: %s", step.Name()) |
| 161 | } |
| 162 | stepNames[step.Name()] = true |
| 163 | } |
| 164 | |
| 165 | if w.AddWorkflowHistory && w.DB == nil { |
| 166 | // 警告:启用了历史但没有数据库 |
| 167 | fmt.Println("Warning: workflow history enabled but no database configured") |
| 168 | } |
| 169 | |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | // ValidateInput 验证输入 |
| 174 | func (w *Workflow) ValidateInput(input any) error { |