From 7ff6ea2df69729f16a64b90c80ea0ab7d505a1f7 Mon Sep 17 00:00:00 2001 From: li1234yun Date: Mon, 7 Jun 2021 16:20:59 +0800 Subject: [PATCH] Fix custom middleware sample code interface implementation error Fix custom middleware sample code interface implementation error, interface function declare error. --- .../middleware/middleware-overview.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/daprdocs/content/en/developing-applications/middleware/middleware-overview.md b/daprdocs/content/en/developing-applications/middleware/middleware-overview.md index 8bc5df72b2d..751bac28f76 100644 --- a/daprdocs/content/en/developing-applications/middleware/middleware-overview.md +++ b/daprdocs/content/en/developing-applications/middleware/middleware-overview.md @@ -49,7 +49,7 @@ spec: ## Writing a custom middleware -Dapr uses [FastHTTP](https://github.com/valyala/fasthttp) to implement its HTTP server. Hence, your HTTP middleware needs to be written as a FastHTTP handler. Your middleware needs to implement a middleware interface, which defines a **GetHandler** method that returns a **fasthttp.RequestHandler**: +Dapr uses [FastHTTP](https://github.com/valyala/fasthttp) to implement its HTTP server. Hence, your HTTP middleware needs to be written as a FastHTTP handler. Your middleware needs to implement a middleware interface, which defines a **GetHandler** method that returns **fasthttp.RequestHandler** and **error**: ```go type Middleware interface { @@ -60,14 +60,16 @@ type Middleware interface { Your handler implementation can include any inbound logic, outbound logic, or both: ```go -func GetHandler(metadata Metadata) fasthttp.RequestHandler { + +func (m *customMiddleware) GetHandler(metadata Metadata) (func(fasthttp.RequestHandler) fasthttp.RequestHandler, error) { + var err error return func(h fasthttp.RequestHandler) fasthttp.RequestHandler { return func(ctx *fasthttp.RequestCtx) { // inboud logic h(ctx) // call the downstream handler // outbound logic } - } + }, err } ```