ducky/devices
2015-12-19
Parent:a700ede02f91
ducky/devices/vendor/github.com/pborman/uuid/sql.go
Fix JSON pointers in errors when creating devices. Our JSON pointers used to point at the root of the document, but the properties were actually in objects in an array keyed off of "devices", so we had to update the field property of our errors to match. While we were in there, we fixed the "insufficient" error for a Device's name to be "missing" when the name is an empty string. So far, the only way for a Device's name for it to be insufficient is _for it to be the empty string_, but if in the future we raise the minimum length of the Device name, there will be a distinction and I'd like the code to recognise it.
| 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 } |