Documentation ¶
Overview ¶
Package goji contains Goji (https://github.com/zenazn/goji) middleware for reporting events to Apinalytics.
To get started go to http://apinalytics.tanktop.tv/u to get an application Id and write key.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildMiddleWare ¶
func BuildMiddleWare(applicationId, writeKey, url string, callback func(c *web.C, event *cli.AnalyticsEvent, r *http.Request), ) func(c *web.C, h http.Handler) http.Handler
BuildMiddleware builds middleware for Goji that reports HTTP requests to Apinalytics.
Add it to your Goji mux m as follows.
m.Use(BuildMiddleWare(myAppId, myWriteKey, "http://apinalytics.tanktop.tv/1/event/", nil))
To add your own data to the events reported add a callback. The main use for this at the moment is to record the ID of the API consumer.
callback := func(c *web.C, event *apinalytics_client.AnalyticsEvent, r *http.Request) { event.ConsumerId = c.Env["api_user"].(string) } m.Use(BuildMiddleWare(myAppId, myWriteKey, "http://apinalytics.tanktop.tv/1/event/", callback))
The middleware sets the following event fields: Timestamp, Method, Url, ResponseUS, StatusCode. It will also set Function if you record the name of the endpoint/method handling function in c.Env["function"] - e.g. if you have a function GetEvent that handles GET /api/1/event/:itemtype/ you might record the function name as follows.
func GetEvent(c web.C, w http.ResponseWriter, r *http.Request) { c.Env["function"] = "GetEvent" item_type_str := c.URLParams["itemtype"] : : }
Types ¶
This section is empty.