-
Notifications
You must be signed in to change notification settings - Fork 18k
Proposal: net/url: add Values.Decode #32634
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
Comments
Seems reasonable overall. At least two questions that need to be decided though:
|
I'd make this work similar to other encoders like encoding/json. That is, if any data is already present, the decoding inserts/appends, instead of replacing entire values. |
/cc @bradfitz for thoughts |
The behavior on duplicate values seems kinda arbitrary. Are we sure that's what others would usually want? And is this more for performance or for convenience? If performance, what about the case when you only want a certain field and don't care to do the allocations for any others? The most general API might be callback-based where a user func can choose which to decode (perhaps even lazily decoding keys and/or values) and when to stop iteration. But if it's just convenience, sure. But I might choose a more verbose name to make it clear what the overwrite-vs-append behavior is. |
This isn't for performance; I didn't even benchmark or measure anything. It's convenience; I found this somewhat simple use case needed an unexpected amount of boilerplate.
Hmm, if we're not sure about this, then it's probably best to reject this proposal. I'd prefer the user having to write an extra five lines, over us having a new bit of API that needs careful documentation so that users know what it does. The user's five extra lines would already obviously show what the code is meant to do. |
The previous comment by @mvdan (the original author) suggests declining this proposal. |
No comments, so proposal declined. |
Right now, if one wants to decode an URL query string into an existing non-nil Values map, the only way is something like:
This means an extra allocation, and the piece of boilerplate seems like it should be unnecessary.
I think this would be much nicer, to mirror the
Encode() string
method we already have:The implementation would be trivial. We already have a
parseQuery(m Values, query string) (err error)
function, so it could be moved to the method, andParseQuery
could use the method directly.The text was updated successfully, but these errors were encountered: