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

🔥 Feature: add queryBool parser #2329

Merged
merged 3 commits into from
Feb 9, 2023
Merged

Conversation

dozheiny
Copy link
Contributor

@dozheiny dozheiny commented Feb 9, 2023

Hi!
Before this PR, I wrote this feature for integer variables #2306 And float variables #2328.
Now I wrote this feature for boolean variables,
With this parser, you can easily extract bool values from URL queries. You can pass the desired key and the URL string to the parser, which will return the boolean value associated with that key. This eliminates manual string parsing and makes retrieving the values you need easier.

@li-jin-gou
Copy link
Contributor

Next time PR can be merged, as the functions are similar

@dozheiny
Copy link
Contributor Author

dozheiny commented Feb 9, 2023

Next time PR can be merged, as the functions are similar

Yes, you are right. I will resolve conflict files.

@dozheiny dozheiny reopened this Feb 9, 2023
@dozheiny
Copy link
Contributor Author

dozheiny commented Feb 9, 2023

I don't know why PR closed; I think because pulled resolved conflicts.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM

@li-jin-gou li-jin-gou merged commit c3b151a into gofiber:master Feb 9, 2023
@crdx
Copy link

crdx commented Mar 28, 2023

This may not be the right place for this but I didn't want to clog up the issues list with a simple question.

What's the reason for QueryBool() returning true for a non-existent key? Since the default value of a bool in Go is false, I would have expected it to be false here too.

@dozheiny
Copy link
Contributor Author

dozheiny commented Mar 29, 2023

Most frameworks (in other languages, not just in Go) will calculate the boolean value true actual if it is a string.
That means If the convert fails, it returns true (with an error).

@crdx
Copy link

crdx commented Mar 29, 2023

Yes, in the string case true is returned and that's expected. I'm talking about in the case of the parameter not existing at all. The documentation for QueryBool has a warning saying this, as well:

Please note if that parameter is not in the request, true will be returned.

Compare to QueryFloat:

Please note if that parameter is not in the request, zero will be returned.

0 is the zero value for a float, so that's what is returned. For a bool false is the zero value, so shouldn't it be what's returned? To me it makes as much sense as QueryFloat returning an arbitrary value like 123 if the key doesn't exist.

I can't think of a situation where you want to query a non-existent key and get true back if it doesn't exist... what am I missing here?

@dozheiny
Copy link
Contributor Author

No. I think you are right.

@ReneWerner87
Copy link
Member

@dozheiny can you provide a PR with a change (function, docs)

@dozheiny
Copy link
Contributor Author

Sure, I'll do it.

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.

5 participants