Puzzle 9 Explanation: Go Time API
Explore how Go's encoding/json package handles time.Time serialization and why comparing time values using == can fail. Understand the difference between wall clock and monotonic clock readings, and learn to use t.Equal for accurate time comparisons in Go.
We'll cover the following...
We'll cover the following...
Try it yourself
Try executing the code below to see the result for yourself.
Explanation
You might expect this code to fail since there’s no time type in the JSON format, or you might expect the comparison to succeed.
Go’s encoding/json package lets us define custom JSON serialization for types that JSON does not support. We do that by implementing json.Marshaler and json.Unmarshaler interfaces. Go’s ...