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 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) }