rs/xhandler

Composable stacks of middleware?

Closed this issue · 3 comments

Hey,

Thanks for this awesome project!

I was wondering what your thoughts would be about adding support for composable stacks of middleware, kind of like this project.

It can already be quite verbose calling Use and UseC for every piece of middleware that you want to incorporate, but when you start having different middleware chains for different routes it can get a bit repetitive.

I'm thinking something like:

std := xhandler.Chain{}
std.UseStack(close, timeout, logger, stats) // alternatively UseS?
...
auth := std.Append(jwt, cors)

would be a pretty nice convenience to have.

To add middleware that are not context aware, maybe we could do something similar to the project above, such as:

std.UseStack(close, timeout, logger, xhandler.Adapt(cors, jwt))
rs commented

Love the idea. I'd use Stack over UseStack to make it even more concise.

Great! I'll see what I can whip up in the next little while.

+1 for this! Alice-like middleware chaining is really neat!