Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for express.js-like middleware. With this patch, multiple functions can be called for any given endpoint, which allows you add functionality in a compositional manner.
You can specify global middleware that is called for all requests:
And you can specify middleware on a per-endpoint basis:
Not every function in the chain has to be called. A function can "bail" the request and circumvent the execution of further middleware by calling
ctx.Finish()
. e.g. ifbasicAuth
in the above examples set some headers and calledctx.Finish()
because the authentication failed,sayHello
will not be called.Unit tests have been added as well, although I'm not confident that this patch is bug-free. A second pair of eyes would help greatly since I'm not too familiar with this codebase, especially the altered logic in
routeHandler
.