2016-12-10 14:16:05 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2016-12-11 14:50:01 +01:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2016-12-24 15:12:01 +02:00
|
|
|
|
|
|
|
"github.com/dannyvankooten/ana/count"
|
2016-12-10 14:16:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// URL: /api/visitors/count
|
|
|
|
var GetVisitorsCountHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2016-12-11 14:50:01 +01:00
|
|
|
before, after := getRequestedPeriods(r)
|
|
|
|
result := count.Visitors(before, after)
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(result)
|
2016-12-10 14:16:05 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// URL: /api/visitors/count/realtime
|
|
|
|
var GetVisitorsRealtimeCountHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2016-12-24 15:12:01 +02:00
|
|
|
result := count.RealtimeVisitors()
|
2016-12-11 14:50:01 +01:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(result)
|
2016-12-10 14:16:05 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// URL: /api/visitors/count/group/:period
|
|
|
|
var GetVisitorsPeriodCountHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2016-12-11 14:50:01 +01:00
|
|
|
before, after := getRequestedPeriods(r)
|
|
|
|
results := count.VisitorsPerDay(before, after)
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(results)
|
2016-12-10 14:16:05 +01:00
|
|
|
})
|