Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MiddlewareBuilder ¶
type MiddlewareBuilder struct { StatusCode int // The HTTP status code that the middleware will set on the response. Data []byte // Data is a slice of bytes to be potentially used as the HTTP response body. Log func(ctx *mist.Context) // Log is a function to execute logging operations within the middleware scope, receiving a context with relevant request information. }
MiddlewareBuilder is a struct that encapsulates configuration options for creating HTTP middleware. The struct stores a status code for the HTTP response, a slice of bytes that can be used as response data, and a logging function that can be executed with a given context during the middleware's operation.
func (MiddlewareBuilder) Build ¶
func (m MiddlewareBuilder) Build() mist.Middleware
Build is a method on the MiddlewareBuilder struct that constructs and returns a new middleware. The middleware created by this method is designed to intercept the processing of an HTTP request, allowing for actions to be taken before or after the next handler in the chain is called. The middleware also includes panic recovery, which sets a predefined response and logs the panic using the provided log function.
Returns:
- mist.Middleware: This is the middleware function that conforms to the mist.Middleware type. It takes the next handler in the chain and returns a new handler that performs the middleware's operations.
Example usage:
mb := MiddlewareBuilder{ StatusCode: 500, Data: []byte("Internal Server Error"), Log: func(ctx *mist.Context) { // Implementation of logging when a panic occurs }, }
middleware := mb.Build() // This middleware can then be used to wrap around any mist.HandleFunc to apply the logic defined in Build.