bot icon indicating copy to clipboard operation
bot copied to clipboard

[FEATURE] Skip global middlewares execution on specific handlers

Open Forceres opened this issue 3 months ago • 2 comments

It'd great to skip some middlewares execution on specific handlers (e.g. auth middleware for public handlers). Now we can only make these middlewares not global and explicitly pass them to RegisterHandler.

Forceres avatar Nov 10 '25 15:11 Forceres

I believe that such a mechanism would be worse than useful for the following reasons:

  1. Additional checks would need to be performed at run time, which could lead to performance degradation.
  2. It would complicate the library architecture by adding additional arguments, conditions, exceptions, and edge cases.

If there is a need to use only certain middleware, then when registering each handler, you can pass middleware specific to it.

And in order not to duplicate the code, you can simply create groups of middleware functions that will be presented as a collection. And pass one or another group to the function in which they should work.

steindvart avatar Nov 11 '25 11:11 steindvart

I don't think that mechanism is so complicated and would lead to real performance degradation. The lib already has lots of checks, so one more or one less, it doesn't really matter. But DX is really important in such libs.

Forceres avatar Nov 11 '25 12:11 Forceres