-
Notifications
You must be signed in to change notification settings - Fork 43
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
Pointer to int and zero value #48
Comments
@badoux could you provide a more complete example? I'm not 100% clear on the issue you are describing. |
Hi @deankarn Here is a full example :
• |
Gorilla schema has a ZeroEmpty method to deal with this case : |
why you expect the |
Hey @badoux As @gunawanwijaya eluded to if the key exists with no value, the value IS blank. There is no way to differentiate using URL.Values But for an int, if it’s not a valid int then we can differentiate. I’m not sure I want to add an option like that at this time. If you want the int to be 0 even if no value is sent you can change your strict from +int to just int as the default value will be 0. |
Simply because i need to know if a value is given or not. So if the value of r.ID is 0 i can know that the user given me an "empty" value ("" or "0") and want to set this value to NULL in database, if the pointer is still nil i can't know It's already the same behaviour with a *string. If no value is given it's nil, otherwise it's the given string or "". Like @deankarn said "if the key exists with no value, the value IS blank", and if it's blank... it's not nil. Seems logical to me but i can understand, i will stick to gorilla/schema for this usecase cause i need it and its the default behaviour. |
When providing empty value for "test_string" parameter(r.Form["test_string"]=""), Request.TestString will be not nil and set with the zero value "" as wanted.
But when "test_int" is provided with an empty string value(r.Form["test_int"]=""), Request.TestInt is still nil and shloud rather be set to the zero value 0.
It works great with Gorilla Schema
The text was updated successfully, but these errors were encountered: