diff --git a/README.md b/README.md index 8d08bf0..f59dfdb 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,9 @@ Context is an exceptionally useful feature in golang, but a common complaint is The boring standard library solves this by using parametric polymorphism. Context is by default an empty object passed through the chain, and each function/set of context parameters is an additional trait condition applied at compile time. ``` -pub func tracing_middleware(handler: func(http.Request, mut http.Response)){ +type HTTPRequest = async func(Ctx, http.Request, mut http.Response) + +pub func tracing_middleware(handler: HTTPRequest){ return async func(ctx: Ctx, req: http.Request, resp: mut http.Response) { with tracing.NewSpan(ctx, 'request_duration') { await handler(ctx, req, resp) @@ -96,7 +98,7 @@ pub func tracing_middleware(handler: func(http.Request, mut http.R } } -pub func auth_middleware(handler: func(http.Request, mut http.Response), scope: Str){ +pub func auth_middleware(handler: HTTPRequest, scope: Str){ return async func(ctx: Ctx, req: http.Request, resp: mut http.Response) { if ctx.has_scope(scope) { await handler(ctx, req, resp) @@ -106,7 +108,7 @@ pub func auth_middleware(handler: func(http.Request, mut http.Respons } } -pub func cancel_middleware(handler: func(http.Request, mut http.Response)){ +pub func cancel_middleware(handler: HTTPRequest){ return async func(ctx: Ctx, req: http.Request, resp: mut http.Response) { if !(await ctx.is_cancelled()) { // check cancel token await handler(ctx, req, resp)