Integration Guide - Go SDK

Built For Software License Source Code

Send API call data to Moesif API Analytics

Source Code on GitHub

How to install

Run the following commands:

go get github.com/moesif/moesifmiddleware-go

Configuration options

Please note the request is the original http.Request and the response is moesifResponseRecorder.

// Moesif Response Recorder
 type MoesifResponseRecorder struct {
	 rw http.ResponseWriter
	 status int
	 writer io.Writer
	 header map[string][]string
 }

Application_Id

(required), string, is obtained via your Moesif Account, this is required.

Should_Skip

(optional) (request, response) => boolean, a function that takes a request and a response, and returns true if you want to skip this particular event.

Identify_User

(optional, but highly recommended) (request, response) => string, a function that takes a request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically, but different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.

Get_Metadata

(optional) (request, response) => dictionary, a function that takes a request and response, and returns a dictionary (must be able to be encoded into JSON). This allows you to associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.

Get_Session_Token

(optional) (request, response) => string, a function that takes a request and response, and returns a string that is the session token for this event. Moesif tries to get the session token automatically, but if this doesn’t work for your service, you should use this to identify sessions.

Mask_Event_Model

(optional) (EventModel) => EventModel, a function that takes an EventModel and returns an EventModel with desired data removed. The return value must be a valid EventModel required by Moesif data ingestion API. For details regarding EventModel please see the Moesif Golang API Documentation.

Debug

(optional) boolean, a flag to see debugging messages.

Capture_Outoing_Requests

(optional) boolean, Default False. Set to True to capture all outgoing API calls from your app to third parties like Stripe or to your own dependencies while using net/http package. The options below is applied to outgoing API calls. When the request is outgoing, for options functions that take request and response as input arguments, the request and response objects passed in are Request request and Response response objects.

Should_Skip_Outgoing

(optional) (request, response) => boolean, a function that takes a request and response, and returns true if you want to skip this particular event.

Identify_User_Outgoing

(optional, but highly recommended) (request, response) => string, a function that takes request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically, but different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.

Get_Metadata_Outgoing

(optional) (request, response) => dictionary, a function that takes request and response, and returns a dictionary (must be able to be encoded into JSON). This allows to associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.

Get_Session_Token_Outgoing

(optional) (request, response) => string, a function that takes request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.

Mask_Event_Model_Outgoing

(optional) (EventModel) => EventModel, a function that takes an EventModel and returns an EventModel with desired data removed. The return value must be a valid EventModel required by Moesif data ingestion API. For details regarding EventModel please see the Moesif Golang API Documentation.

Example

An example app with Moesif integration is available on GitHub.

Other integrations

To view more more documentation on integration options, please visit the Integration Options Documentation.