ProcessRequestOneOf reads a JSON blob for the request and makes sure it contains one of a set of keywords. For example, a request might have the ('foo' && 'bar') keys, OR it might have the 'baz' key. In either case, we want to accept the request; however, if none of these sets shows up, the request
(r *http.Request, keywordSets [][]string)
| 112 | // none of these sets shows up, the request is a bad request, and it |
| 113 | // should be returned. |
| 114 | func ProcessRequestOneOf(r *http.Request, keywordSets [][]string) (map[string]string, []string, error) { |
| 115 | blob, err := readRequestBlob(r) |
| 116 | if err != nil { |
| 117 | return nil, nil, err |
| 118 | } |
| 119 | |
| 120 | var matched []string |
| 121 | for _, set := range keywordSets { |
| 122 | if matchKeywords(blob, set) { |
| 123 | if matched != nil { |
| 124 | return nil, nil, errors.NewBadRequestString("mismatched parameters") |
| 125 | } |
| 126 | matched = set |
| 127 | } |
| 128 | } |
| 129 | if matched == nil { |
| 130 | return nil, nil, errors.NewBadRequestString("no valid parameter sets found") |
| 131 | } |
| 132 | return blob, matched, nil |
| 133 | } |
| 134 | |
| 135 | // ProcessRequestFirstMatchOf reads a JSON blob for the request and returns |
| 136 | // the first match of a set of keywords. For example, a request |
searching dependent graphs…