Scan implements the sql.Scanner interface. A 16-byte slice will be handled by UnmarshalBinary, while a longer byte slice or a string will be handled by UnmarshalText.
(src interface{})
| 27 | // A 16-byte slice will be handled by UnmarshalBinary, while |
| 28 | // a longer byte slice or a string will be handled by UnmarshalText. |
| 29 | func (u *UUID) Scan(src interface{}) error { |
| 30 | switch src := src.(type) { |
| 31 | case UUID: // support gorm convert from UUID to NullUUID |
| 32 | *u = src |
| 33 | return nil |
| 34 | |
| 35 | case []byte: |
| 36 | if len(src) == Size { |
| 37 | return u.UnmarshalBinary(src) |
| 38 | } |
| 39 | return u.UnmarshalText(src) |
| 40 | |
| 41 | case string: |
| 42 | return u.UnmarshalText([]byte(src)) |
| 43 | } |
| 44 | |
| 45 | return fmt.Errorf("uuid: cannot convert %T to UUID", src) |
| 46 | } |
| 47 | |
| 48 | // NullUUID can be used with the standard sql package to represent a |
| 49 | // UUID value that can be NULL in the database. |
no test coverage detected