fathom/api/browsers.go
2016-12-23 17:52:08 +02:00

23 lines
478 B
Go

package api
import (
"encoding/json"
"net/http"
"github.com/dannyvankooten/ana/count"
)
// URL: /api/browsers
var GetBrowsersHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
before, after := getRequestedPeriods(r)
// get total
total := count.Visitors(before, after)
// get rows
results := count.Browsers(before, after, getRequestedLimit(r), total)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(results)
})