Skip to content

🚀 Feature: Add idempotency middleware (v2 backport)#2288

Merged
ReneWerner87 merged 2 commits intogofiber:masterfrom
leonklingele:add-idempotency-middleware-backport-v2
Jan 13, 2023
Merged

🚀 Feature: Add idempotency middleware (v2 backport)#2288
ReneWerner87 merged 2 commits intogofiber:masterfrom
leonklingele:add-idempotency-middleware-backport-v2

Conversation

@leonklingele
Copy link
Member

@leonklingele leonklingele commented Jan 6, 2023

Description

Add idempotency middleware.
Implements #2163.

This is a v2 backport of #2253.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • For new functionalities I follow the inspiration of the express js framework and built them similar in usage
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation - https://github.com/gofiber/docs for https://docs.gofiber.io/
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • If new dependencies exist, I have checked that they are really necessary and agreed with the maintainers/community (we want to have as few dependencies as possible)
  • I tried to make my code as fast as possible with as few allocations as possible
  • For new code I have written benchmarks so that they can be analyzed and improved

* 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
@leonklingele
Copy link
Member Author

CI is failing for some unrelated data race.

Copy link
Member

@efectn efectn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to me after creating a PR for docs repo

@leonklingele
Copy link
Member Author

@efectn why is this even required? It's a 1:1 copy of the README here, why can't this be automated as follows?

# From inside the docs repo:
git clone --depth 1 https://github.com/gofiber/fiber
find fiber/middleware -maxdepth 2 -name 'README.md' -exec bash -c 'MW="$(basename $(dirname {}))" ; cp "{}" "api/middleware/$MW.md"' \;
rm -rf fiber

@ReneWerner87 ReneWerner87 merged commit adcf92d into gofiber:master Jan 13, 2023
@ReneWerner87
Copy link
Member

i will create the docs PR, shortly before the release

@leonklingele
Copy link
Member Author

Nice! I noticed that the docs in this repo slightly differ from the ones in the docs repo. Can you make sure they are a identical copy? Simply use the commands from above.. Thank you! 😊

@ReneWerner87
Copy link
Member

I think there is a reason for this :D

@ReneWerner87
Copy link
Member

Later, when we are on docusaurus, by the way, the idea is to
To remove the doc repository and maintain and use all the documentation in the core repository.

@leonklingele
Copy link
Member Author

I think there is a reason for this :D

The doc repo for example uses space-indentation for code while this repo uses tabs. There should not be a reason for that ;)

Later, when we are on docusaurus, by the way, the idea is to To remove the doc repository and maintain and use all the documentation in the core repository.

That would be awesome! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants