ducky/devices
ducky/devices/vendor/github.com/pborman/uuid/sql.go
Add endpoint for retrieving devices. Add an endpoint for retrieving devices, either as a list or by ID. Stub endpoints for updating and deleting devices., along with TODOs marking them as things to still be completed. (Right now, accessing those endpoints is an insta-panic.) Simplify our handleCreateDevices by returning StatusUnauthorized if AuthUser fails, so we can reserve StatusForbidden for when auth succeeds but access is still denied. Also, delay the instantiation and allocation of a Response variable until we're actually going to use it. Create a handleGetDevices handler that authenticates the user, and if no ID is set, returns a list of all their Devices. If one or more IDs are set, only those Devices are returned. If ScopeViewPushToken is one of the scopes associated with the request, the push tokens for each Device will be included in the response. Otherwise, they will be omitted.
| 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 } |