We abstracted this out into something a little different; each handler is an “action”, i.e. takes a request and returns a result (makes control flow easier to reason about). Then middleware is just a function that takes an “action” and returns an “action”, i.e. wraps the input action with more stuff. Then you can just chain them per route, or set defaults app wide.
I ended up writing a few middleware handlers following the pattern mentioned here so I could use alice to chain them. Combining this with popular community middleware made it easy to write robust servers.
We abstracted this out into something a little different; each handler is an “action”, i.e. takes a request and returns a result (makes control flow easier to reason about). Then middleware is just a function that takes an “action” and returns an “action”, i.e. wraps the input action with more stuff. Then you can just chain them per route, or set defaults app wide.
Used here: https://github.com/blendlabs/go-web
This makes me think of the Redux pattern used with React! Neat idea!
I ended up writing a few middleware handlers following the pattern mentioned here so I could use alice to chain them. Combining this with popular community middleware made it easy to write robust servers.