ducky/devices
18:b2fdf827758e
Go to Latest
ducky/devices/vendor/code.secondbit.org/uuid.hg/uuid.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.
7 "github.com/pborman/uuid"
10 var InvalidIDError = errors.New("Invalid ID format.")
15 return ID(uuid.NewRandom())
18 func (id ID) String() string {
19 return uuid.UUID(id).String()
22 func (id ID) IsZero() bool {
32 func (id ID) Copy() ID {
33 resp, _ := Parse(id.String())
34 // ignore the error because they asked for a copy of the ID, they
35 // never asked if it was valid or not.
36 // This is, overall, not the most efficient way to do this (we're
37 // essentially converting to a string and then back again) but the
38 // computational complexity involved is pretty minor, and it allows
39 // us to respect the boundaries between the packages, using only the
40 // exported interfaces to perform a copy. And that seems pretty
45 func (id ID) MarshalJSON() ([]byte, error) {
46 return uuid.UUID(id).MarshalJSON()
49 func (id ID) Value() (driver.Value, error) {
50 return id.String(), nil
53 func (id *ID) Scan(src interface{}) error {
54 return (*uuid.UUID)(id).Scan(src)
57 func (id *ID) UnmarshalJSON(in []byte) error {
58 return (*uuid.UUID)(id).UnmarshalJSON(in)
61 func Parse(in string) (ID, error) {
62 id := ID(uuid.Parse(in))
64 return id, InvalidIDError
69 func (id ID) Equal(other ID) bool {
70 return uuid.Equal(uuid.UUID(id), uuid.UUID(other))