-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
all: decide what can implement TextMarshaler/TextUnmarshaler #10275
Comments
This isn't possible to change now, as it would change the encodings produced by programs that exist today. |
@rsc Let me push back just a little on that, I don't see why it's necessarily true. For example, again taking encoding/json with time.Time & Duration: I don't see a reason why the time.SetJSON method couldn't accept as input the string that's currently emitted. I can see why you'd want to change the output of time.Duration, but I'm not sure why it'd be a problem to make the SetJSON method accept both the new output format (e.g., "5s") and the old (which is nanoseconds, without quotes). Those cases are super easy to distinguish. ...I agree the generalized cross product of types w/ encodings is probably going to have many much more difficult cases. |
Replying to a comment from 2015, but we can't change the encoding outputs now because then if a new version of Go is sending data to an older version, the older version will not understand it. |
That means it'd have to be opt in, e.g. with paired |
It means it would have to wait for Go 2. |
If we change this in Go 2--if we add marshaling methods for standard library types--we will have to provide some mechanism for Go 2 programs to read Go 1 data. One approach would be to only add marshaling methods in new versions of the packages, and to permit the old and new versions of the package to both be imported in the same program. |
@rsc Would you consider implementing Unmarshal interfaces? We can do this right now, can't we? #25705 Was closed because apparently implementing UnmarshalText in net/url would break existing code. Maybe I am missing it, so please correct me if I am wrong, but I don't see how that is true. There are plenty of use cases for code that parses URLs and this seems like an easy fix. |
- add validation as extra step after migration - add missing json struct tags to new v1alpha3 config fields - add unit tests - add missing `omitempty` tags to configs to avoid (un-)marshalling issues - drop `string` type for `time.Duration` type field in JSON Schema (doesn't work properly sometimes due to broken handling of time.Duration as per golang/go#10275)
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/496537 mentions this issue: |
All Tunnel timeout values are based on seconds however, there isn't a great way to do this in a flexible way with Go due to `time.Duration` not having marshal/unmarshal support in Go 1[1]. Instead, we introduce a custom `TunnelDuration` value here and ensure it always converts durations into seconds without impacting other users of `time.Duration`. [1]: golang/go#10275
All Tunnel timeout values are based on seconds however, there isn't a great way to do this in a flexible way with Go due to `time.Duration` not having marshal/unmarshal support in Go 1[1]. Instead, we introduce a custom `TunnelDuration` value here and ensure it always converts durations into seconds without impacting other users of `time.Duration`. [1]: golang/go#10275
All Tunnel timeout values are based on seconds however, there isn't a great way to do this in a flexible way with Go due to `time.Duration` not having marshal/unmarshal support in Go 1[1]. Instead, we introduce a custom `TunnelDuration` value here and ensure it always converts durations into seconds without impacting other users of `time.Duration`. [1]: golang/go#10275
Due to marshal/unmarshal support lacking in Go 1[1], we were previously sending nanosecond values to the API instead of the required seconds. This would have resulted in higher than usual timeout durations (10 seconds would have been sent as 1000000000 seconds since it duration unmarshals to nanoseconds). Updates all the instances of time duration handling in `cloudflare_tunnel_config` resource to use the newly introduced `TunnelDuration` to ensure we correctly setting the units. [1]: golang/go#10275
Due to marshal/unmarshal support lacking in Go 1[1], we were previously sending nanosecond values to the API instead of the required seconds. This would have resulted in higher than usual timeout durations (10 seconds would have been sent as 1000000000 seconds since it duration unmarshals to nanoseconds). Updates all the instances of time duration handling in `cloudflare_tunnel_config` resource to use the newly introduced `TunnelDuration` to ensure we correctly setting the units. [1]: golang/go#10275
All Tunnel timeout values are based on seconds however, there isn't a great way to do this in a flexible way with Go due to `time.Duration` not having marshal/unmarshal support in Go 1[1]. Instead, we introduce a custom `TunnelDuration` value here and ensure it always converts durations into seconds without impacting other users of `time.Duration`. [1]: golang/go#10275
Due to marshal/unmarshal support lacking in Go 1[1], we were previously sending nanosecond values to the API instead of the required seconds. This would have resulted in higher than usual timeout durations (10 seconds would have been sent as 1000000000 seconds since it duration unmarshals to nanoseconds). Updates all the instances of time duration handling in `cloudflare_tunnel_config` resource to use the newly introduced `TunnelDuration` to ensure we correctly setting the units. [1]: golang/go#10275
For example, the standard library has a decent encoding/json package, and a great time.Duration object. But these objects don't play well together; if you want to encode a Duration in a json blob, you'll have to make a custom type that calls .String()/ParseDuration() when Get/SetJSON are called. It would be nice if they worked together by default.
...Unfortunately, the cross product of all the useful encoding packages with all the useful types in the standard library is probably quite large, so I'll understand if you say "no" to that. Perhaps at least time.Time and time.Duration could be supported?
The text was updated successfully, but these errors were encountered: