middleware

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 3 Imported by: 0

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

type ConfirmFunc

type ConfirmFunc func(context.Context, *blades.Message) (bool, error)

ConfirmFunc is a callback used by the confirmation middleware to decide whether a prompt should proceed. It returns true to allow execution, false to deny, and may return an error to abort.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL