-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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]: Adding Default Value Support for QueryParser #2571
Comments
@gopkg-dev I would like to take this up. Could you please assign the same to me? |
As pointed out by @hi019 in the issue #1306, a go-default package with similar functionality to our current need already exists. One potential solution is to simply incorporate the aforementioned package into QueryParser (since this package has been tried and tested and is widely used, we are confident in its accuracy and can announce that the go-default default functionality is now supported). // QueryParser binds the query string to a struct.
func (c *Ctx) QueryParser(out interface{}) error {
data := make(map[string][]string)
var err error
// populating data map with query params...
// set defaults in out struct before processing query parameters.
defaults.SetDefaults(out)
return c.parseToStruct(queryTag, out, data)
} @ReneWerner87 @gopkg-dev Thoughts? |
But then we can use that outside and we just mention it in the documentation for a possible solution to the problem Since this is independent and can be used separately I would not increase the fiber code and dependencies with it Because this packet can then also be used for use with the body or header parser just before the structs are passed into the methods |
Yes, that makes sense. However, considering our aim is to incorporate this functionality within struct tags, we would need to decide between utilizing or building a tag parser mechanism and using reflection to populate the fields. As you suggested, we could advise developers to leverage an external library for this purpose (could be go-default or maybe any other). Alternatively, I'm open to the idea of developing a custom implementation if that aligns better with our goals. I'd be interested to hear your thoughts on this or any other potential implementations you might have in mind |
The https://github.com/mcuadros/go-defaults package hasn't been updated in years, is there an alternative. |
Hey Guys, Can you assign me if this problem is not updating |
Done |
Closing since v3 has got this feature. |
Feature Description
Currently, QueryParser in Fiber does not support setting default values for query parameters directly in the struct. This enhancement request suggests adding the ability to define default values for query parameters within the struct tags.
Additional Context (optional)
#1306
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: