parseFilter extracts MessageFilter fields from query parameters.
(r *http.Request)
| 292 | |
| 293 | // parseFilter extracts MessageFilter fields from query parameters. |
| 294 | func parseFilter(r *http.Request) MessageFilter { |
| 295 | q := r.URL.Query() |
| 296 | f := MessageFilter{ |
| 297 | To: q.Get("to"), |
| 298 | From: q.Get("from"), |
| 299 | Cc: q.Get("cc"), |
| 300 | Subject: q.Get("subject"), |
| 301 | SubjectContains: q.Get("subject_contains"), |
| 302 | SubjectRegex: q.Get("subject_regex"), |
| 303 | BodyContains: q.Get("body_contains"), |
| 304 | Project: q.Get("project"), |
| 305 | Order: q.Get("order"), |
| 306 | } |
| 307 | if f.Order == "" { |
| 308 | f.Order = "desc" |
| 309 | } |
| 310 | if s := q.Get("since"); s != "" { |
| 311 | f.Since = parseTimestamp(s) |
| 312 | } |
| 313 | if u := q.Get("until"); u != "" { |
| 314 | f.Until = parseTimestamp(u) |
| 315 | } |
| 316 | if l := q.Get("limit"); l != "" { |
| 317 | if n, err := strconv.Atoi(l); err == nil && n > 0 { |
| 318 | f.Limit = n |
| 319 | } |
| 320 | } |
| 321 | if o := q.Get("offset"); o != "" { |
| 322 | if n, err := strconv.Atoi(o); n >= 0 && err == nil { |
| 323 | f.Offset = n |
| 324 | } |
| 325 | } |
| 326 | return f |
| 327 | } |
| 328 | |
| 329 | // unixFloat converts a time.Time to a float64 unix timestamp with microsecond |
| 330 | // precision (matching the internal event.Event.Timestamp representation). |
no test coverage detected