Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Confirm ¶
func Confirm(confirm ConfirmFunc) blades.Middleware
Confirm returns a Middleware that invokes the provided confirmation callback before delegating to the next Handler. If confirmation is denied, it returns ErrInterrupted. If the callback returns an error, that error is propagated.
func Retry ¶
func Retry(attempts int, opts ...retry.Option) blades.Middleware
Retry returns a middleware that retries handlers with configurable retry behavior.
Parameters:
attempts: The total number of attempts to execute the handler, including the initial attempt.
For example, attempts=3 means up to 3 tries (1 initial + 2 retries).
opts: Optional configuration for retry behavior. See retry.Option (from github.com/go-kratos/kit/retry) for details.
Behavior:
- The same invocation is passed to the handler on each attempt. Handlers must not mutate the invocation.
- If all attempts are exhausted and the handler continues to return an error, the last error is returned.
- Successfully generated messages from failed attempts are not replayed on subsequent retries.
- Retry behavior (e.g., backoff, which errors are retryable) can be customized via retry.Option.
- Context cancellation is respected during retry attempts.
Example usage:
// Retry up to 5 times with exponential backoff, only on specific errors.
mw := Retry(5,
retry.WithBackoff(retry.NewExponentialBackoff()),
retry.WithRetryable(func(err error) bool {
return IsRetryableError(err)
}),
)
Types ¶
Click to show internal directories.
Click to hide internal directories.