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:
+18
-1
@@ -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{} {
|
||||
|
||||
Reference in New Issue
Block a user