mirror of
https://github.com/google/uuid.git
synced 2025-09-16 09:16:30 +02:00
Merge pull request #19 from dansouza/master
altered uuid.Scan() so that it allows for empty UUIDs to be read ...
This commit is contained in:
10
sql.go
10
sql.go
@@ -15,6 +15,11 @@ import (
|
|||||||
func (uuid *UUID) Scan(src interface{}) error {
|
func (uuid *UUID) Scan(src interface{}) error {
|
||||||
switch src.(type) {
|
switch src.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
// if an empty UUID comes from a table, we return a null UUID
|
||||||
|
if src.(string) == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// see uuid.Parse for required string format
|
// see uuid.Parse for required string format
|
||||||
parsed := Parse(src.(string))
|
parsed := Parse(src.(string))
|
||||||
|
|
||||||
@@ -26,6 +31,11 @@ func (uuid *UUID) Scan(src interface{}) error {
|
|||||||
case []byte:
|
case []byte:
|
||||||
b := src.([]byte)
|
b := src.([]byte)
|
||||||
|
|
||||||
|
// if an empty UUID comes from a table, we return a null UUID
|
||||||
|
if len(b) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// assumes a simple slice of bytes if 16 bytes
|
// assumes a simple slice of bytes if 16 bytes
|
||||||
// otherwise attempts to parse
|
// otherwise attempts to parse
|
||||||
if len(b) == 16 {
|
if len(b) == 16 {
|
||||||
|
Reference in New Issue
Block a user