-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: net/url: implement TextMarshaler/TextUnmarshaler interfaces for url.URL #52638
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
Comments
I think this would be good, but is it a breaking change? Right now, the output of this code u, _ := url.Parse("http://example.com")
b, _ := json.Marshal(u)
fmt.Println(string(b)) is
I think it would be better if the output were "http://example.com" but maybe someone somewhere would miss the old output? |
@carlmjohnson nice catch!
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This proposal has been added to the active column of the proposals project |
It seems like JSON decoding the { } form might still work since that's not a JSON string, so it won't try the TextUnmarshaler. So an old encoding might be readable by a new Go where URL implements these methods. The reverse would not be true. Have we decided before whether this is OK? I seem to remember JSON encoding of IP addresses used to be base64 byte encodings, but I think we decided that was just so broken we could fix it. Not changing the JSON seems like a big inconsistency too since I assume the goal here is to get better JSON support for URLs (in addition to flag support). |
#5086 for |
Thanks very much for that list, @seankhliao! It looks like we should merge this one into #10275 too, and then bring 10275 over to the non-Go2 proposal process. |
This proposal is a duplicate of a previously discussed proposal, as noted above, |
In order to be able to pass
url.URL
variable toflag.TextVar(&url, ...)
,url.URL
type must implementencoding.TextMarshaler
andencoding.TextUnmarshaler
interfaces.This approach was suggested here instead of making a dedicated
flag.URLVar
function inflag
package.The text was updated successfully, but these errors were encountered: