Skip to content

proposal: net/url: preserve order of URL Query parameters instead of sorting them alphabetically #29985

@tiger5226

Description

@tiger5226

What version of Go are you using (go version)?

master

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

N/A

What did you do?

I was leveraging a go library for restful api communication, and ran into a frustrating issue where the url parameters were being sorted alphabetically. Normally, this does not matter. However, with the advent of HMAC Signing and many APIs using it now, this becomes a problem. The idea is that you sign the url which in a GET situation includes the url parameters and append a new hmac_sign parameter to the end. This works fine in many languages except Go.

I don't know for sure why the go team decided to do this. I suspect that the decision was made to use map[string]string to hold the url parameters. Since maps do not guarantee an order, a sort was done to make the return deterministic.

I would like to suggest this be backed by an array so it can be possible to preserve an order to support the above mentioned use case. This allows libraries to also support ordering while still depending on the core Go libraries.

What did you expect to see?

I expect that as I set parameters the order is maintained when I call the encode function.

What did you see instead?

Instead they are sorted alphabetically.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions