fromHTTP panics with an httputil value on failure
(req *http.Request)
| 338 | |
| 339 | // fromHTTP panics with an httputil value on failure |
| 340 | func (r *WithAttrRequest) fromHTTP(req *http.Request) { |
| 341 | r.Signer = blob.ParseOrZero(req.FormValue("signer")) |
| 342 | r.Value = req.FormValue("value") |
| 343 | fuzzy := req.FormValue("fuzzy") // exact match if empty |
| 344 | fuzzyMatch := false |
| 345 | if fuzzy != "" { |
| 346 | lowered := strings.ToLower(fuzzy) |
| 347 | if lowered == "true" || lowered == "t" { |
| 348 | fuzzyMatch = true |
| 349 | } |
| 350 | } |
| 351 | r.Attr = req.FormValue("attr") // all attributes if empty |
| 352 | if r.Attr == "" { // and force fuzzy in that case. |
| 353 | fuzzyMatch = true |
| 354 | } |
| 355 | r.Fuzzy = fuzzyMatch |
| 356 | max := req.FormValue("max") |
| 357 | if max != "" { |
| 358 | maxR, err := strconv.Atoi(max) |
| 359 | if err != nil { |
| 360 | panic(httputil.InvalidParameterError("max")) |
| 361 | } |
| 362 | r.N = maxR |
| 363 | } |
| 364 | r.N = r.n() |
| 365 | if at := req.FormValue("at"); at != "" { |
| 366 | r.At = time.Time(types.ParseTime3339OrZero(at)) |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | // n returns the sanitized maximum number of search results. |
| 371 | func (r *WithAttrRequest) n() int { |
no test coverage detected