ducky/devices

Paddy 2016-01-02 Parent:a700ede02f91

19:51ad0db105c8 Go to Latest

ducky/devices/vendor/github.com/pborman/uuid/sql.go

Update trout to fix routing bug. Update to tip on trout to fix the routing bug that was causing us such issues. See the commit message of trout at 3df515f0cec5 for more details.

History
paddy@16 1 // Copyright 2015 Google Inc. All rights reserved.
paddy@16 2 // Use of this source code is governed by a BSD-style
paddy@16 3 // license that can be found in the LICENSE file.
paddy@16 4
paddy@16 5 package uuid
paddy@16 6
paddy@16 7 import (
paddy@16 8 "errors"
paddy@16 9 "fmt"
paddy@16 10 )
paddy@16 11
paddy@16 12 // Scan implements sql.Scanner so UUIDs can be read from databases transparently
paddy@16 13 // Currently, database types that map to string and []byte are supported. Please
paddy@16 14 // consult database-specific driver documentation for matching types.
paddy@16 15 func (uuid *UUID) Scan(src interface{}) error {
paddy@16 16 switch src.(type) {
paddy@16 17 case string:
paddy@16 18 // see uuid.Parse for required string format
paddy@16 19 parsed := Parse(src.(string))
paddy@16 20
paddy@16 21 if parsed == nil {
paddy@16 22 return errors.New("Scan: invalid UUID format")
paddy@16 23 }
paddy@16 24
paddy@16 25 *uuid = parsed
paddy@16 26 case []byte:
paddy@16 27 // assumes a simple slice of bytes, just check validity and store
paddy@16 28 u := UUID(src.([]byte))
paddy@16 29
paddy@16 30 if u.Variant() == Invalid {
paddy@16 31 return errors.New("Scan: invalid UUID format")
paddy@16 32 }
paddy@16 33
paddy@16 34 *uuid = u
paddy@16 35 default:
paddy@16 36 return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
paddy@16 37 }
paddy@16 38
paddy@16 39 return nil
paddy@16 40 }