diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-28 13:05:23 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-28 13:05:23 -0700 |
commit | 8ff77bc0aa766dcd33fd4458557444defa76d87b (patch) | |
tree | d28b4790f7d45d96be15a98c2d4adc4caed0e50d /system/api/handlers.go | |
parent | c178f2e403b0b711d8aa3c0155d1368827f88afd (diff) |
adding initial components for anayltics tracking API requests
Diffstat (limited to 'system/api/handlers.go')
-rw-r--r-- | system/api/handlers.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/system/api/handlers.go b/system/api/handlers.go index a56a667..8356683 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/bosssauce/ponzu/content" + "github.com/bosssauce/ponzu/system/api/analytics" "github.com/bosssauce/ponzu/system/db" ) @@ -210,9 +211,6 @@ func SendJSON(res http.ResponseWriter, j map[string]interface{}) { sendData(res, data, 200) } -// ResponseFunc ... -type ResponseFunc func(http.ResponseWriter, *http.Request) - // CORS wraps a HandleFunc to response to OPTIONS requests properly func CORS(next http.HandlerFunc) http.HandlerFunc { return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { @@ -224,3 +222,12 @@ func CORS(next http.HandlerFunc) http.HandlerFunc { next.ServeHTTP(res, req) }) } + +// Record wraps a HandleFunc to record API requests for analytical purposes +func Record(next http.HandlerFunc) http.HandlerFunc { + return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + go analytics.Record(req) + + next.ServeHTTP(res, req) + }) +} |