ogen icon indicating copy to clipboard operation
ogen copied to clipboard

gen: middleware support

Open screwyprof opened this issue 3 years ago • 5 comments

Description

At the moment the project uses a custom static router which doesn’t support middleware.

It would be great if it was possible to add support for different types of middleware:

  1. middleware which runs for all requests
  2. middleware that runs per endpoint

References

screwyprof avatar Nov 07 '22 13:11 screwyprof

We have ogen/middleware (that is 1) and (2) looks like #566

ernado avatar Nov 07 '22 15:11 ernado

Thanks for the quick response.

screwyprof avatar Nov 07 '22 17:11 screwyprof

Also, you could use Server.FindRoute method (2).

https://ogen.dev/docs/concepts/static_router/#findroute-method

ghost avatar Nov 07 '22 21:11 ghost

Would be great to have more information exposed (entire Route struct) inside the middleware context.

I came across a situation where I have a external module implementing the middleware that need the Route.pathPattern field. In that situation I can't use (1) because the Request struct doesn't have the needed field and (2) does not work because i can't/doesn't want to import generated code to be able to call FindRoute

Any ideas ?

biancalana avatar May 04 '23 18:05 biancalana

We have ogen/middleware

How to add those middlewares? Docs has zero information about it. Ok, we have created func Logging(logger *zap.Logger) middleware.Middleware {...} then what? How it would be in execution chain?

inglar avatar Oct 28 '25 13:10 inglar