validateEventConfigOptions returns errors for all invalid event type options.
(eventType db.EventType, eventConfig *EventConfig)
| 1524 | |
| 1525 | // validateEventConfigOptions returns errors for all invalid event type options. |
| 1526 | func validateEventConfigOptions(eventType db.EventType, eventConfig *EventConfig) error { |
| 1527 | if eventConfig == nil || eventConfig.Options == nil { |
| 1528 | return nil |
| 1529 | } |
| 1530 | |
| 1531 | var errs *base.MultiError |
| 1532 | |
| 1533 | switch eventType { |
| 1534 | case db.DocumentChange: |
| 1535 | for k, v := range eventConfig.Options { |
| 1536 | switch k { |
| 1537 | case db.EventOptionDocumentChangedWinningRevOnly: |
| 1538 | if _, ok := v.(bool); !ok { |
| 1539 | errs = errs.Append(fmt.Errorf("Event option %q must be of type bool", db.EventOptionDocumentChangedWinningRevOnly)) |
| 1540 | } |
| 1541 | default: |
| 1542 | errs = errs.Append(fmt.Errorf("unknown option %q found for event type %q", k, eventType)) |
| 1543 | } |
| 1544 | } |
| 1545 | default: |
| 1546 | errs = errs.Append(fmt.Errorf("unknown options %v found for event type %q", eventConfig.Options, eventType)) |
| 1547 | } |
| 1548 | |
| 1549 | // If we only have 1 error, return it as-is for clarity in the logs. |
| 1550 | if errs.ErrorOrNil() != nil { |
| 1551 | if errs.Len() == 1 { |
| 1552 | return errs.Errors[0] |
| 1553 | } |
| 1554 | return errs |
| 1555 | } |
| 1556 | |
| 1557 | return nil |
| 1558 | } |
| 1559 | |
| 1560 | // Initialize event handlers, if present |
| 1561 | func (sc *ServerContext) initEventHandlers(ctx context.Context, dbcontext *db.DatabaseContext, config *DbConfig) (err error) { |
no test coverage detected