Skip to content

Proposal: net/url: add Values.Decode #32634

@mvdan

Description

@mvdan

Right now, if one wants to decode an URL query string into an existing non-nil Values map, the only way is something like:

values2, err := url.ParseQuery(query)
if err != nil {
    ...
}
for key, value := range values2 {
    values[key] = append(values[key], value...)
}

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:

if err := values.Decode(query); err != nil {
    ...
}

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, and ParseQuery could use the method directly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions