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
net/url: add a "SetQuery" helper function #24552
Comments
Possible implementation: #24528 |
It seems to me like your second piece of code could be:
What are you trying to solve here? If it's less code, I think both ways to do it currently are fine. If it's about the code being confusing, then perhaps better documentation or an example could help. Or perhaps even a proposal to improve a future version of net/url, such as replacing |
@mvdan I think the problem with using RawQuery and Encode() is the amount of voodoo involved. It feels strange to me that the normal way to construct a URL with query parameters is to assign anything called So I was trying to take something that confused and bewildered me about Go when I started writing it professionally a year ago (and still looks odd to me), and then simplify it for the next guy. |
There are no existing Setter functions on But if we added one, I'd name it And the implementation could be simpler. I replied on https://go-review.googlesource.com/c/go/+/102476 /cc @bcmills |
I don't have a strong opinion on whether we should add a That suggests a slightly broader change to bring func (u *URL) SetEscapedPath(rawPath string) error {
path, err := PathUnescape(path)
if err != nil {
return err
}
u.RawPath = rawPath
u.Path = path
return nil
}
func (u *URL) SetQuery(Values) {
[…]
} |
@bcmills Should there also be a |
@HaraldNordgren Since the |
Please, let's not start designing new API for url.URL. The URL struct is not set up for incremental modification. It's meant for reading URLs, not to be a kitchen sink for writing them. There's a reason that APIs that consume URLs typically take type string. |
Yeah, I'd prefer we keep URL as it is, without any setters. We can rethink the URL type for Go 2, perhaps. |
Hi, I want to create a new helper function called "SetQueryParameters" in net/url. Is this something the community wants too?
Already from my first experience with Go, I was confused about the round-about way that we set query parameters:
So instead we could have a helper function
to hopefully make life a tiny bit easier for me and other developers.
The text was updated successfully, but these errors were encountered: