A Middleware is an interface used to modify or handle an email message before it is processed. Multiple middlewares can be applied to a Msg and are executed in FIFO (First-In, First-Out) order.
To implement a middleware, you must satisfy the Middleware interface:
type Middleware interface {
Handle(*Msg) *Msg
Type() MiddlewareType
}
Handle(*Msg) *Msg: Performs the processing logic and must return the modified Msg.Type() MiddlewareType: Returns a unique MiddlewareType to ensure the same middleware is not applied more than once.
You can attach middleware to a message during creation using WithMiddleware(middleware).