func EntityTail(query *entities.Query) server.Handler { return server.Handler( func(req *wcg.Request) response.Response { result := query.MustExecute(req) return response.NewJSONResponse(result.Tail()) }) }
func EntityStreaming(query *entities.Query, includeKeys bool) server.Handler { return server.Handler( func(req *wcg.Request) response.Response { iter := query.MustRun(req) pr, pw := io.Pipe() return response.NewStreamingResponse(&entityStreamer{ req: req, iter: iter, pr: pr, pw: pw, includeKeys: includeKeys, }) }, ) }
func execStatsQuery(req *wcg.Request, query *entities.Query) response.Response { now := lib.Now() until := wcg.ParseDateTimeOr(req.Query("until"), now) if until.After(now) { until = now } sinceDefault := until.Add(StatsQueryDefaultTimeWindow) sinceMin := until.Add(StatsQueryMaxTimeWindow) since := wcg.ParseDateTimeOr(req.Query("since"), until.Add(-24*time.Hour)) if since.After(until) { since = sinceDefault } else if sinceMin.After(since) { since = sinceMin } query = query.Filter("Timestamp >=", since).Filter("Timestamp <", until) if req.Query("device") != "" { query = query.Filter("Device =", req.Query("device")) } return response.NewJSONResponse(query.MustExecute(req).Data) }