ValidateWithContext is the same as Validate but allows specifying the ModelEvent context.
(ctx context.Context, model Model)
| 237 | |
| 238 | // ValidateWithContext is the same as Validate but allows specifying the ModelEvent context. |
| 239 | func (app *BaseApp) ValidateWithContext(ctx context.Context, model Model) error { |
| 240 | if m, ok := model.(PreValidator); ok { |
| 241 | if err := m.PreValidate(ctx, app); err != nil { |
| 242 | return err |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | event := new(ModelEvent) |
| 247 | event.App = app |
| 248 | event.Context = ctx |
| 249 | event.Type = ModelEventTypeValidate |
| 250 | event.Model = model |
| 251 | |
| 252 | return event.App.OnModelValidate().Trigger(event, func(e *ModelEvent) error { |
| 253 | if m, ok := e.Model.(PostValidator); ok { |
| 254 | if err := m.PostValidate(ctx, e.App); err != nil { |
| 255 | return err |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | return e.Next() |
| 260 | }) |
| 261 | } |
| 262 | |
| 263 | // ------------------------------------------------------------------- |
| 264 |
no test coverage detected