Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEventHandler ¶
func NewEventHandler[T any](opts ...Option[T]) event.EventHandler[T]
NewEventHandler creates a callback-enabled event handler that sends HTTP callbacks based on event processing results.
The handler supports custom logger configuration; if none provided, it extracts logger from context or uses default logging.
Parameters:
- opts: Configuration options to customize behavior
Returns:
- event.EventHandler[T]: Configured callback event handler
Example:
handler := NewEventHandler[UserData](
WithHTTPClient(customClient),
WithCallbackConfig(5, 3*time.Second, 30*time.Second),
WithLogger(customLogger),
)
Types ¶
type CallbackEventMessage ¶
type CallbackEventMessage[T any] struct { event.BaseEventMessage[T] Callback *CallbackInfo `json:"callback"` }
CallbackEventMessage extends BaseEventMessage with HTTP callback functionality. It embeds the standard event message structure and adds callback URL configuration for sending notifications based on event processing results.
JSON Structure:
{
"event_type": "user.created",
"timestamp": "2023-01-01T12:00:00Z",
"payload": { /* your event data */ },
"metadata": { "source": "api" },
"callback": {
"success_url": "https://api.example.com/success",
"fail_url": "https://api.example.com/failure"
}
}
func (*CallbackEventMessage[T]) GetCallback ¶
func (m *CallbackEventMessage[T]) GetCallback() *CallbackInfo
GetCallback returns the callback configuration for this event message. Used by the callback handler to determine which URLs to call based on event processing results.
type CallbackHTTPError ¶ added in v0.19.0
type CallbackHTTPError struct {
StatusCode int // HTTP status code from response
Status string // HTTP status text
URL string // Target URL that failed
}
CallbackHTTPError represents HTTP-specific errors from callback requests. Enables proper error classification for retry decisions.
func (*CallbackHTTPError) Error ¶ added in v0.19.0
func (e *CallbackHTTPError) Error() string
Error implements the error interface for CallbackHTTPError.
type CallbackInfo ¶
type CallbackInfo struct {
SuccessURL string `json:"success_url"` // URL called when event processing succeeds
FailURL string `json:"fail_url"` // URL called when event processing fails
}
CallbackInfo contains HTTP callback URLs for event processing notifications. Supports separate URLs for success and failure scenarios, enabling flexible webhook delivery patterns based on processing outcomes.
type Option ¶
type Option[T any] func(*callbackEventHandler[T])
Option is a function type for configuring the callback event handler.
func WithCallbackConfig ¶
func WithCallbackConfig[T any](maxRetries int, retryInterval time.Duration, callbackTimeout time.Duration) Option[T]
WithCallbackConfig configures retry behavior and timeouts for callbacks. Allows customization of retry attempts, intervals, and request timeouts.
func WithHTTPClient ¶
WithHTTPClient configures a custom HTTP client for callback requests. Use to customize timeout, transport, or authentication settings.
func WithLogger ¶
func WithLogger[T any](customLogger common_logger.Logger) Option[T]
WithLogger configures a custom logger for the event handler. If not provided, logger will be extracted from context or use default.