Skip to content

Commit 9905ddd

Browse files
committed
support empty value for any type with IsZero() method
1 parent 50c87b2 commit 9905ddd

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

query/encode.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ type Encoder interface {
5151
// - the field is empty and its tag specifies the "omitempty" option
5252
//
5353
// The empty values are false, 0, any nil pointer or interface value, any array
54-
// slice, map, or string of length zero, and any time.Time that returns true
55-
// for IsZero().
54+
// slice, map, or string of length zero, and any type (such as time.Time) that
55+
// returns true for IsZero().
5656
//
5757
// The URL parameter name defaults to the struct field name but can be
5858
// specified in the struct field's tag value. The "url" key in the struct
@@ -294,8 +294,12 @@ func isEmptyValue(v reflect.Value) bool {
294294
return v.IsNil()
295295
}
296296

297-
if v.Type() == timeType {
298-
return v.Interface().(time.Time).IsZero()
297+
type zeroable interface {
298+
IsZero() bool
299+
}
300+
301+
if z, ok := v.Interface().(zeroable); ok {
302+
return z.IsZero()
299303
}
300304

301305
return false

0 commit comments

Comments
 (0)