ProcessRequestFirstMatchOf reads a JSON blob for the request and returns the first match of a set of keywords. For example, a request might have one of the following combinations: (foo=1, bar=2), (foo=1), and (bar=2) By giving a specific ordering of those combinations, we could decide how to accept
(r *http.Request, keywordSets [][]string)
| 138 | // By giving a specific ordering of those combinations, we could decide how to accept |
| 139 | // the request. |
| 140 | func ProcessRequestFirstMatchOf(r *http.Request, keywordSets [][]string) (map[string]string, []string, error) { |
| 141 | blob, err := readRequestBlob(r) |
| 142 | if err != nil { |
| 143 | return nil, nil, err |
| 144 | } |
| 145 | |
| 146 | for _, set := range keywordSets { |
| 147 | if matchKeywords(blob, set) { |
| 148 | return blob, set, nil |
| 149 | } |
| 150 | } |
| 151 | return nil, nil, errors.NewBadRequestString("no valid parameter sets found") |
| 152 | } |
| 153 | |
| 154 | func matchKeywords(blob map[string]string, keywords []string) bool { |
| 155 | for _, keyword := range keywords { |
searching dependent graphs…