Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGinEventHandler ¶
func NewGinEventHandler[T any](ginHandler GinEventHandlerFunc[T], eventHandler event.EventHandler[T]) gin.HandlerFunc
NewGinEventHandler creates a Gin HTTP handler that processes incoming JSON requests as events. It integrates event processing lifecycle with HTTP request handling, providing automatic JSON unmarshaling, event handler hooks, and standardized HTTP responses.
Request Processing Flow:
- Read and validate JSON request body
- Unmarshal JSON into typed event message
- Execute BeforeHandle hook for pre-processing
- Run business logic via ginHandler function
- Execute AfterHandle hook for post-processing
- Return appropriate HTTP response (200 OK or error status)
Parameters:
- ginHandler: Business logic function that processes the event
- eventHandler: Event handler providing unmarshaling and lifecycle hooks
Returns:
- gin.HandlerFunc: HTTP handler ready for Gin route registration
Types ¶
type GinEventHandlerFunc ¶
GinEventHandlerFunc defines a function that processes business logic for an event message. This function receives the Gin context and typed event message, returning an error if business processing fails.
Parameters:
- ctx: Gin context with HTTP request/response and framework utilities
- msg: Typed event message containing payload and metadata
Returns:
- error: Business logic error (nil indicates success)
Example:
func processUserEvent(ctx *gin.Context, msg event.EventMessage[UserData]) error {
userData := msg.GetPayload()
return userService.CreateUser(ctx.Request.Context(), userData)
}
Click to show internal directories.
Click to hide internal directories.