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.
For some use cases, the server may want to perform actions after the user's request has been serviced. Examples include:
For these purposes, I have added
Endware
as a solution.Endware
is ahttp.Handler
alias that allows alice users to create "after the fact" middleware in a similar way to how they create regular middleware.Endware
is executed after all constructors and handlers have been invoked byThen(h)
/ThenFunc(h)
.Using endware is simple:
chain := alice.New(m1, m2)
becomes
chainWithEndware := alice.New(m1, m2).Finally(e1, e2)
This leads the flow of
chainWithEndware.Then(h)
to be
m1 -> m2 -> h -> e1 -> e2
The
Append()
functionality has been mirrored inAppendEndware()
, as well asExtend
being augmented to also extend endware.AfterFuncs()
andAppendEndwareFuncs()
are convenience method for those not dealing withhttp.Handler
s directly.This is still a WIP, just wanted to open it so you could take a look at your leisure.
Sorry in advance if this is not the way you are supposed to contribute code