How to: Author middleware components
Dapr allows custom processing pipelines to be defined by chaining a series of middleware components. In this guide, you’ll learn how to create a middleware component. To learn how to configure an existing middleware component, see Configure middleware components
Your middleware needs to implement a middleware interface, which defines a GetHandler method that returns a http.Handler callback and an error:
Your handler implementation can include an inbound logic, outbound logic, or both:
func (m *customMiddleware) GetHandler(metadata middleware.Metadata) (func(next http.Handler) http.Handler, error) {
var err error
return func(next http.Handler) http.Handler {
// Inbound logic
// ...
// Call the next handler
// ...
}
}