nil receiver
parent
ac10a7a79c
commit
6b4ca5231f
|
@ -6,11 +6,17 @@ import (
|
|||
"sourcecode.social/reiver/go-erorr"
|
||||
)
|
||||
|
||||
const errNilReceiver = erorr.Error("opt: nil receiver")
|
||||
|
||||
var _ json.Unmarshaler = new(Optional[bool])
|
||||
var _ json.Unmarshaler = new(Optional[string])
|
||||
|
||||
// UnmarshalJSON makes it so json.Unmarshaler is implemented.
|
||||
func (receiver *Optional[T]) UnmarshalJSON(data []byte) error {
|
||||
if nil == receiver {
|
||||
return errNilReceiver
|
||||
}
|
||||
|
||||
switch interface{}(&receiver.value).(type) {
|
||||
case *bool, *string, json.Unmarshaler:
|
||||
// these are OK.
|
||||
|
|
Loading…
Reference in New Issue