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: Path and RawPath are hard to use #17340
Comments
You are on the right track with
This yields a
In this case, your That said, you should probably also be using We do not use our issue tracker for questions; please see the resources at https://golang.org/wiki/Questions for help debugging code. |
Lack of the leading
Still, I wasn't asking a question (though I'm glad to have this improved workaround), but requesting a feature: The ability to specify the path as a slice of segments. This allows me to avoid knowing what to escape ( |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.6 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
I wanted to create a URL where a path segment had an encoded slash. This is because usernames in our system are allowed to contain any valid UTF-8 character, and usernames are used in URLs. But getting the url package to properly encode the slash is tricky. Sample code:
What did you expect to see?
What did you see instead?
Of course I understand that it's impossible for this example to know that "foo/bar" is a single path segment, instead of two. But I tried also supplying a raw path:
But the output was the same. The only way I've been able to figure out how to get it to know that "foo/bar" is a single segment is by manually encoding each segment myself and then having the url package parse it:
This outputs the correct value:
However, since the whole point of constructing a URL from its parts it to generate a string representation (e.g., to pass to
http.Get()
), this kind of defeats the whole purpose: I can simply use theraw
variable.I'd like a way to be able to specify the path as a slice of segments, so that the url package knows which parts are directory segments and which aren't. Something like:
The text was updated successfully, but these errors were encountered: