| 36 | } |
| 37 | |
| 38 | func findFeatureArray(dec *json.Decoder) error { |
| 39 | for { |
| 40 | t, err := dec.Token() |
| 41 | if err == io.EOF { |
| 42 | break |
| 43 | } |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | if s, ok := t.(string); ok && s == "features" && dec.More() { |
| 48 | // we found the features element |
| 49 | d, err := dec.Token() |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | if delim, ok := d.(json.Delim); ok { |
| 54 | if delim.String() == "[" { |
| 55 | // we have our start of the array |
| 56 | break |
| 57 | } else { |
| 58 | // A different kind of delimiter |
| 59 | return fmt.Errorf("Expected features to be an array.") |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if !dec.More() { |
| 66 | return fmt.Errorf("Cannot find any features.") |
| 67 | } |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | func main() { |
| 72 | flag.Parse() |