1
0
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:
pborman
2016-02-08 13:05:45 -08:00

10
sql.go
View File

@@ -15,6 +15,11 @@ import (
func (uuid *UUID) Scan(src interface{}) error {
switch src.(type) {
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
parsed := Parse(src.(string))
@@ -26,6 +31,11 @@ func (uuid *UUID) Scan(src interface{}) error {
case []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
// otherwise attempts to parse
if len(b) == 16 {