Skip to content
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

Return same url.URL struct instead of string #18

Closed
xeoncross opened this issue Oct 21, 2016 · 3 comments
Closed

Return same url.URL struct instead of string #18

xeoncross opened this issue Oct 21, 2016 · 3 comments

Comments

@xeoncross
Copy link

Why does the NormalizeURL() function take a url.URL but return a string? There are already functions for dealing with string URL's.

@mna
Copy link
Member

mna commented Oct 21, 2016

Hello David,

Typically this is passed to http.Get or http.NewRequest, and the url.URL is a pointer, so the URL you passed in is modified and normalized in-place, no need to return it. If you need the url.URL, you can just use the one you passed in. (There's a minor caveat to this regarding the urlesc package which doesn't escape in-place)

Martin

@xeoncross
Copy link
Author

So since the urlesc.Escape() method simply returns a string, then if I don't pass the result of NormalizeURL() back to url.Parse() then I'll lose some of the proper escaping done by urlesc and possibly end up with a less-than-normalized URL.

@mna
Copy link
Member

mna commented Oct 22, 2016

Recent versions of Go properly escape, so that call to urlesc should not be necessary now. So your url.URL would be ok (see #14 that I haven't had time to address yet).

@mna mna closed this as completed Oct 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants