MCPcopy
hub / github.com/perkeep/perkeep / fromHTTP

Method fromHTTP

pkg/search/handler.go:340–368  ·  view source on GitHub ↗

fromHTTP panics with an httputil value on failure

(req *http.Request)

Source from the content-addressed store, hash-verified

338
339// fromHTTP panics with an httputil value on failure
340func (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.
371func (r *WithAttrRequest) n() int {

Callers 1

Calls 3

nMethod · 0.95
ParseOrZeroFunction · 0.92
InvalidParameterErrorTypeAlias · 0.92

Tested by

no test coverage detected