2
0

Range types Set method supports its own type, string, and nil

Previously Set would always return an error when called on a range type.
Now it will accept an instance of itself, a pointer to an instance of
itself, a string, or nil. Strings are parsed with the same logic as
DecodeText.
This commit is contained in:
Jack Christensen
2020-03-03 15:25:57 -06:00
parent 55a56add23
commit 8117205a75
8 changed files with 192 additions and 7 deletions
+18 -1
View File
@@ -16,7 +16,24 @@ type Numrange struct {
}
func (dst *Numrange) Set(src interface{}) error {
return errors.Errorf("cannot convert %v to Numrange", src)
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = Numrange{Status: Null}
return nil
}
switch value := src.(type) {
case Numrange:
*dst = value
case *Numrange:
*dst = *value
case string:
return dst.DecodeText(nil, []byte(value))
default:
return errors.Errorf("cannot convert %v to Numrange", src)
}
return nil
}
func (dst Numrange) Get() interface{} {