Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor Ctx.Method func to improve code readability #2647

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

dairlair
Copy link
Contributor

@dairlair dairlair commented Sep 25, 2023

Description

I've simplified the function by breaking it down into three trivially simple steps:

Step One: We check if no arguments are provided in the override parameter, in which case we have no choice but to return c.method. If arguments are provided, we proceed to step two.

Step Two: We take the first string from override and validate if it's a valid HTTP Method name. If it's not, it's evident that we need to return the current method from the context. If it is valid, we move on to step three.

Now, in step three, we have a valid HTTP Method in the override parameter. We save this method and its code to the context and return the method's name as a string.

This pull request doesn't fix any bugs, but it improves the code's readability.

I decided to submit these changes because my younger sister (a budding programmer with a diagnosis of semantic dyslexia) asked me to explain what this function does, and I had to put in some effort to understand what was happening and explain to her that two consecutive 'if' statements are better than two nested ones. 🧡

Type of change

  • Code quality improvement

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
  • New and existing unit tests pass locally with my changes
  • I tried to make my code as fast as possible with as few allocations as possible

Commit formatting:

Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/

🎨

@welcome
Copy link

welcome bot commented Sep 25, 2023

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Copy link
Member

@sixcolors sixcolors left a comment

Choose a reason for hiding this comment

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

Great job on the PR! LGTM. Thanks for your contribution 🧼

@sixcolors sixcolors changed the title Refactor Ctx.Method func to improve code readability ♻️ Refactor Ctx.Method func to improve code readability Sep 25, 2023
@ReneWerner87 ReneWerner87 merged commit c89184c into gofiber:master Sep 26, 2023
20 checks passed
@welcome
Copy link

welcome bot commented Sep 26, 2023

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

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