fathom/api/referrers.go
2016-12-24 10:00:45 +02:00

23 lines
481 B
Go

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