validateHook checks if a hook configuration is valid. It ensures the URL and type are set correctly, and sets default values for timeout and retry count if missing. Parameters: - hook: The hook to validate. Returns: - error: An error if validation fails.
(hook *Hook)
| 361 | // Returns: |
| 362 | // - error: An error if validation fails. |
| 363 | func validateHook(hook *Hook) error { |
| 364 | if hook.URL == "" { |
| 365 | return fmt.Errorf("hook URL is required") |
| 366 | } |
| 367 | if hook.Type != PreTransaction && hook.Type != PostTransaction { |
| 368 | return fmt.Errorf("invalid hook type: %s", hook.Type) |
| 369 | } |
| 370 | if hook.Timeout <= 0 { |
| 371 | hook.Timeout = 30 // Default timeout |
| 372 | } |
| 373 | if hook.RetryCount < 0 { |
| 374 | hook.RetryCount = 3 // Default retry count |
| 375 | } |
| 376 | return nil |
| 377 | } |
| 378 | |
| 379 | // getTypeKey returns the Redis key for a specific hook type set. |
| 380 | // |