RegisterHook registers a new webhook in Redis. It assigns a new ID if not provided, validates the hook configuration, and stores it in both the main registry and type-specific sets. Parameters: - ctx: The context for the operation. - hook: The hook configuration to register. Returns: - error: An e
(ctx context.Context, hook *Hook)
| 74 | // Returns: |
| 75 | // - error: An error if registration fails. |
| 76 | func (m *redisHookManager) RegisterHook(ctx context.Context, hook *Hook) error { |
| 77 | if hook.ID == "" { |
| 78 | hook.ID = model.GenerateUUIDWithSuffix("hook") |
| 79 | } |
| 80 | hook.CreatedAt = time.Now() |
| 81 | |
| 82 | // Validate hook |
| 83 | if err := validateHook(hook); err != nil { |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | // Store hook in Redis |
| 88 | key := fmt.Sprintf("%s:%s", hookKeyPrefix, hook.ID) |
| 89 | data, err := json.Marshal(hook) |
| 90 | if err != nil { |
| 91 | return fmt.Errorf("failed to marshal hook: %w", err) |
| 92 | } |
| 93 | |
| 94 | // Store in main hook registry |
| 95 | if err := m.client.Set(ctx, key, data, 0).Err(); err != nil { |
| 96 | return fmt.Errorf("failed to store hook: %w", err) |
| 97 | } |
| 98 | |
| 99 | // Add to type-specific set for faster lookups |
| 100 | typeKey := getTypeKey(hook.Type) |
| 101 | if err := m.client.SAdd(ctx, typeKey, hook.ID).Err(); err != nil { |
| 102 | return fmt.Errorf("failed to add hook to type set: %w", err) |
| 103 | } |
| 104 | |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | // UpdateHook updates an existing webhook in Redis. |
| 109 | // It retrieves the existing hook, updates its fields while preserving metadata, |
nothing calls this directly
no test coverage detected