| 250 | } |
| 251 | |
| 252 | func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { |
| 253 | suffix := httputil.PathSuffix(req) |
| 254 | |
| 255 | handlers := getHandler |
| 256 | switch { |
| 257 | case httputil.IsGet(req): |
| 258 | // use default from above |
| 259 | case req.Method == "POST": |
| 260 | handlers = postHandler |
| 261 | default: |
| 262 | handlers = nil |
| 263 | } |
| 264 | fn := handlers[strings.TrimPrefix(suffix, "camli/search/")] |
| 265 | if fn != nil { |
| 266 | fn(h, rw, req) |
| 267 | return |
| 268 | } |
| 269 | |
| 270 | // TODO: discovery for the endpoints & better error message with link to discovery info |
| 271 | ret := camtypes.SearchErrorResponse{ |
| 272 | Error: "Unsupported search path or method", |
| 273 | ErrorType: "input", |
| 274 | } |
| 275 | httputil.ReturnJSON(rw, &ret) |
| 276 | } |
| 277 | |
| 278 | // sanitizeNumResults takes n as a requested number of search results and sanitizes it. |
| 279 | func sanitizeNumResults(n int) int { |