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.
14 func (t *trie) match(input []string) ([]int, bool) {
22 for i := 0; i < num; i++ {
23 // if we're on a nil branch, we're at the end of our line
27 offset = pickNextBranch(b, offset, input[i])
30 // can't find it, bail
34 path, offset = backup(path)
35 offset = offset + 1 // we want the next index from the previously matched one
36 b = b.parent // we need to be picking a branch from our parent, again
37 i = i - 2 // back up to the choice before the one that got us here
39 path = append(path, offset)
40 b = b.children[offset]
52 methods map[string]http.Handler
55 func (b *branch) Less(i, j int) bool {
56 if b.children[i].key == b.children[j].key {
57 return b.children[j].isParam && !b.children[i].isParam
59 return b.children[i].key < b.children[j].key
62 func (b *branch) Len() int {
63 return len(b.children)
66 func (b *branch) Swap(i, j int) {
67 b.children[i], b.children[j] = b.children[j], b.children[i]
70 func (b *branch) addChild(key string, param bool) *branch {
71 child := &branch{key: key, parent: b, isParam: param}
72 if b.children == nil {
73 b.children = []*branch{child}
76 b.children = append(b.children, child)
81 func (b *branch) check(input string) bool {
82 if b.isParam && b.key != "" {
91 func (b *branch) setHandler(method string, handler http.Handler) {
93 b.methods = map[string]http.Handler{}
95 b.methods[method] = handler
98 func pickNextBranch(b *branch, offset int, input string) int {
99 count := len(b.children)
100 for i := offset; i < count; i++ {
101 if b.children[i].check(input) {
108 func backup(path []int) ([]int, int) {
109 last := len(path) - 1