Exemple #1
0
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())
		})
}
Exemple #2
0
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,
			})
		},
	)
}
Exemple #3
0
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)
}