ducky/devices
ducky/devices/apiv1/endpoints.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.
1 package apiv1
3 import (
4 "net/http"
6 "code.secondbit.org/api.hg"
7 "code.secondbit.org/trout.hg"
8 "golang.org/x/net/context"
9 )
11 // GetRouter returns a trout Router that is configured to handle
12 // all the routes necessary to serve a devices API server.
13 func GetRouter(ctx context.Context) http.Handler {
14 var router trout.Router
15 router.Endpoint("/").Methods("POST").Handler(api.ContextWrapper(ctx, api.ContextHandler(handleCreateDevices)))
17 return router
18 }