From 7dc7dee2f45aef296f8e1a7ae68f04a6ba88f22b Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Sat, 24 Dec 2016 15:11:36 +0200 Subject: [PATCH] Get rid of /api/countries endpoint for now. --- api/countries.go | 30 ------------------------------ commands/server.go | 2 +- 2 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 api/countries.go diff --git a/api/countries.go b/api/countries.go deleted file mode 100644 index 52f6da6..0000000 --- a/api/countries.go +++ /dev/null @@ -1,30 +0,0 @@ -package api - -import ( - "encoding/json" - "github.com/dannyvankooten/ana/count" - "net/http" -) - -// URL: /api/countries -var GetCountriesHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - before, after := getRequestedPeriods(r) - - // get total - total := count.Visitors(before, after) - - // get rows - results := count.Custom(` - SELECT - v.country, - COUNT(DISTINCT(pv.visitor_id)) AS count - FROM pageviews pv - LEFT JOIN visitors v ON v.id = pv.visitor_id - WHERE UNIX_TIMESTAMP(pv.timestamp) <= ? AND UNIX_TIMESTAMP(pv.timestamp) >= ? AND v.country IS NOT NULL - GROUP BY v.country - ORDER BY count DESC - LIMIT ?`, before, after, getRequestedLimit(r), total) - - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(results) -}) diff --git a/commands/server.go b/commands/server.go index d3bc853..ea01cc6 100644 --- a/commands/server.go +++ b/commands/server.go @@ -26,7 +26,7 @@ func startServer(port int) { r.Handle("/api/languages", api.Authorize(api.GetLanguagesHandler)).Methods("GET") r.Handle("/api/referrers", api.Authorize(api.GetReferrersHandler)).Methods("GET") r.Handle("/api/screen-resolutions", api.Authorize(api.GetScreenResolutionsHandler)).Methods("GET") - r.Handle("/api/countries", api.Authorize(api.GetCountriesHandler)).Methods("GET") + //r.Handle("/api/countries", api.Authorize(api.GetCountriesHandler)).Methods("GET") r.Handle("/api/browsers", api.Authorize(api.GetBrowsersHandler)).Methods("GET") r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))