π Feature: Add idempotency middleware#2253
Conversation
5593988 to
979bbe3
Compare
5dd8b22 to
4372dd9
Compare
4372dd9 to
f242f13
Compare
There was a problem hiding this comment.
I would argue the same as in the conversation https://github.com/gofiber/fiber/pull/2253/files#r1038919642 to have consistency with fiber.Storage. Otherwise wonderful work!
|
Why did you target Also apply PR template into your PRs please. |
|
@efectn I'll backport this to v2 once merged. |
7dbc78a to
7912335
Compare
|
Soo, finally this is now ready for review. I removed the |
|
Let's make this go in v3 first and I'll open up another PR targeting v2 later on. |
|
Anyone gotten the chance to review this already? I'm working on a project which might benefit from having this. |
|
Will do it tomorrow |
ReneWerner87
left a comment
There was a problem hiding this comment.
implementation looks very good
a few small comments/improvements
- benchmark for the middleware usage would be good, so we can improve it later on
- instead of the clousure i would maybe try to use a function that doesn't need to be created on-the-fly every time
- with the locals thing i'm not quite sure, what happens e.g. if you define the idempotency middleware multiple times, normally there shouldn't be any collisions as they should be used on different routes then ... currently quite not sure with that
- in some places we can optimize and save allocations, like in the ToLower( there exists a fn which does not cause allocations) and other places where only comparisons are done
-> for comparisons no copies need to be made, only if the data should be kept
|
@leonklingele will wait for the others for the feedback and then i merge it @efectn @GalvinGao do you have any other points, otherwise i would merge the pull request |
|
Thanks for the review! Iβll push the updates later today.
Which calls can be optimized? Iβve only found the single call to strings.ToLower used when doing the map lookup which we could replace by utils.ToLower
Also, did you see my question regarding using utils.CopyBytes when storing the request body? I think we need to use it.
|
|
Yes use the copy there, i was not sure about this |
β¦ng unused methods
The real "strings.ToLower" still needs to be used when storing the data.
f334ff0 to
dc6cfb8
Compare
|
I've rebased & addressed @ReneWerner87's points. ptal |
* middleware: add idempotency middleware * middleware/idempotency: use fiber.Storage instead of custom storage * middleware/idempotency: only allocate data if really required * middleware/idempotency: marshal response using msgp * middleware/idempotency: add msgp tests * middleware/idempotency: do not export response * middleware/idempotency: disable msgp's -io option to disable generating unused methods * middleware/idempotency: switch to time.Duration based app.Test * middleware/idempotency: only create closure once * middleware/idempotency: add benchmarks * middleware/idempotency: optimize strings.ToLower when making comparison The real "strings.ToLower" still needs to be used when storing the data. * middleware/idempotency: safe-copy body
* π Feature: Add idempotency middleware (#2253) * middleware: add idempotency middleware * middleware/idempotency: use fiber.Storage instead of custom storage * middleware/idempotency: only allocate data if really required * middleware/idempotency: marshal response using msgp * middleware/idempotency: add msgp tests * middleware/idempotency: do not export response * middleware/idempotency: disable msgp's -io option to disable generating unused methods * middleware/idempotency: switch to time.Duration based app.Test * middleware/idempotency: only create closure once * middleware/idempotency: add benchmarks * middleware/idempotency: optimize strings.ToLower when making comparison The real "strings.ToLower" still needs to be used when storing the data. * middleware/idempotency: safe-copy body * middleware/idempotency: backport to v2
Description
Add idempotency middleware.
Implements #2163.
Type of change
Please delete options that are not relevant.
Checklist: