httphandler

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 3 Imported by: 0

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:

  1. Read and validate JSON request body
  2. Unmarshal JSON into typed event message
  3. Execute BeforeHandle hook for pre-processing
  4. Run business logic via ginHandler function
  5. Execute AfterHandle hook for post-processing
  6. 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

type GinEventHandlerFunc[T any] func(ctx *gin.Context, msg event.EventMessage[T]) error

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)
}

Jump to

Keyboard shortcuts

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