In the mongodb driver for golang there is the following piece of code:
case reflect.Struct:
if z, ok := v.Interface().(Zeroer); ok {
return z.IsZero()
}
return false
Interface Zeroer is defined like this:
type Zeroer interface {
IsZero() bool
}
When I implement my struct with
func (id SomeStruct) IsZero() bool {
return id.ID == ""
}
it works. But when I implement the IsZero method with a pointer receiver:
func (id *SomeStruct) IsZero() bool {
return id.ID == ""
}
the type assertion fails and IsZero does not get executed.
Can someone explain this to me?