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 func parse(l *lexer) ([]*string, error) {
9 pchan := make(chan *string)
10 errchan := make(chan error)
11 done := make(chan struct{})
12 go runParse(l, pchan, errchan, done)
15 case err := <-errchan:
18 parsed = append(parsed, item)
25 func runParse(l *lexer, parsed chan *string, err chan error, done chan struct{}) {
26 var state parseFunc = parseStart
29 state, e = state(l, parsed)
41 type parseFunc func(*lexer, chan *string) (parseFunc, error)
43 func parseEOF(l *lexer, parsed chan *string) (parseFunc, error) {
45 if tok.typ == tokenWhitespace {
48 if tok.typ != tokenEOF {
49 return nil, errors.New("expected EOF, got " + tok.typ.String())
54 func parseStringOrNull(l *lexer, parsed chan *string) (parseFunc, error) {
56 if tok.typ == tokenWhitespace {
58 } else if tok.typ == tokenString {
60 return parseSeparatorOrDelim, nil
61 } else if tok.typ == tokenNull {
63 return parseSeparatorOrDelim, nil
65 return nil, errors.New("expected string, got " + tok.typ.String())
68 func parseSeparatorOrDelim(l *lexer, parsed chan *string) (parseFunc, error) {
70 if tok.typ == tokenWhitespace {
71 return parseSeparatorOrDelim, nil
72 } else if tok.typ == tokenSeparator {
73 return parseStringOrNull, nil
74 } else if tok.typ == tokenArrayEnd {
77 return nil, errors.New("expected separator or delim, got " + tok.typ.String())
80 func parseStart(l *lexer, parsed chan *string) (parseFunc, error) {
82 if tok.typ == tokenWhitespace {
83 return parseStart, nil
84 } else if tok.typ == tokenArrayStart {
85 return parseStringOrNull, nil
87 return nil, errors.New("expected separator or delim, got " + tok.typ.String())