-
Notifications
You must be signed in to change notification settings - Fork 467
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
Support time.Time instead of int64 for date fields #1972
base: beta
Are you sure you want to change the base?
Conversation
@@ -325,6 +326,14 @@ func intEncoder(values *Values, v reflect.Value, keyParts []string, encodeZero b | |||
values.Add(FormatKey(keyParts), strconv.FormatInt(val, 10)) | |||
} | |||
|
|||
func timeEncoder(values *Values, v reflect.Value, keyParts []string, encodeZero bool, _ *formOptions) { | |||
val := v.Interface().(time.Time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if this is called with a v other than a time.Time; does this return an error we need to look for, or will val just be Zero (and is that swallowing an error?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It panics. I think that's OK, but open for other thoughts. It's only called in one location surrounded by
if t == reflect.TypeOf(time.Time{}) {
return timeEncoder
}
so logically, the type assertion v.Interface().(time.Time)
must succeed. I would definitely rather fail fast here rather than silently. The alternative would be to bubble up an error
, but it feels a little weird to return an error
due to a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I'm realizing we have the same panic
behavior in the rest of type assertions in form.go
, so this is really no different than current behavior (where we do a type assertion to an integer:
Line 321 in b384f33
val := v.Int() |
aa2e73f
to
e0418a5
Compare
:lurk: I think the merge-base for this PR should be the |
Why?
This change supports codegen changes that converts datetime fields from
int64
totime.Time
as brought up in this issue: #1205.What?
form.go
fortime.Time
fields. Serialization is performed by reflection, and we do not want the default behavior of inspecting into atime.Time
type, rather just convert it to anint64
Time
,TimeValue
,UnixTime
andUnixValue
to help in creatingtime.Time
and*time.Time
parameter fieldsint64
typeSee Also