{"id":19294714,"url":"https://github.com/moesif/moesifmiddleware-go","last_synced_at":"2025-11-11T20:09:46.657Z","repository":{"id":41081447,"uuid":"172445801","full_name":"Moesif/moesifmiddleware-go","owner":"Moesif","description":"Moesif middleware for Go, for API Monitoring, Analytics, and Monetization.","archived":false,"fork":false,"pushed_at":"2024-09-09T15:26:06.000Z","size":170,"stargazers_count":3,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-01T20:51:28.179Z","etag":null,"topics":["analytics","api-analytics","api-logs","api-management","api-monetization","api-monitoring","go","golang","logger","logging","monitoring","observability","usage-based-billing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Moesif.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":"governance_rules.go","roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-25T06:17:00.000Z","updated_at":"2024-09-10T15:29:19.000Z","dependencies_parsed_at":"2022-08-29T15:01:57.912Z","dependency_job_id":"3c7f8f04-c98f-441e-9655-18702ef5aab8","html_url":"https://github.com/Moesif/moesifmiddleware-go","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesifmiddleware-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesifmiddleware-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesifmiddleware-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesifmiddleware-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moesif","download_url":"https://codeload.github.com/Moesif/moesifmiddleware-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250205978,"owners_count":21392159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","api-analytics","api-logs","api-management","api-monetization","api-monitoring","go","golang","logger","logging","monitoring","observability","usage-based-billing"],"created_at":"2024-11-09T22:39:23.966Z","updated_at":"2025-11-11T20:09:41.634Z","avatar_url":"https://github.com/Moesif.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Moesif Middleware for Go\nby [Moesif](https://moesif.com), the [API analytics](https://www.moesif.com/features/api-analytics) and [API monetization](https://www.moesif.com/solutions/metered-api-billing) platform.\n\n[![Built For][ico-built-for]][link-built-for]\n[![Software License][ico-license]][link-license]\n[![Source Code][ico-source]][link-source]\n\nMoesif middleware for Go logs API calls and sends to [Moesif](https://www.moesif.com) for API analytics and log analysis. This middleware allows you to integrate Moesif's API analytics and \nAPI monetization features into your Go applications with minimal configuration. \n\n\u003e If you're new to Moesif, see [our Getting Started](https://www.moesif.com/docs/) resources to quickly get up and running.\n\n## Prerequisites\nBefore using this middleware, make sure you have the following:\n\n- [An active Moesif account](https://moesif.com/wrap)\n- [A Moesif Application ID](#get-your-moesif-application-id)\n\n### Get Your Moesif Application ID\nAfter you log into [Moesif Portal](https://www.moesif.com/wrap), you can get your Moesif Application ID during the onboarding steps. You can always access the Application ID any time by following these steps from Moesif Portal after logging in:\n\n1. Select the account icon to bring up the settings menu.\n2. Select **Installation** or **API Keys**.\n3. Copy your Moesif Application ID from the **Collector Application ID** field.\n\n\u003cimg class=\"lazyload blur-up\" src=\"images/app_id.png\" width=\"700\" alt=\"Accessing the settings menu in Moesif Portal\"\u003e\n\n## Install the Middleware\nUse `go get`:\n\n```bash\ngo get github.com/moesif/moesifmiddleware-go\n```\n\nIf you are using [Go modules](https://go.dev/ref/mod), you can specify a version number as well:\n\n```bash\ngo get github.com/moesif/moesifmiddleware-go@v1.2.3\n```\n\n## Configure the Middleware\nSee the available [configuration options](#configuration-options) to learn how to configure the middleware for your use case.\n\n## How to Use\n\nThe following snippet shows how to use the middleware:\n\n```go\nimport(\n    moesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc handle(w http.ResponseWriter, r *http.Request) {\n\t// Your API Logic\n}\n\nvar moesifOptions = map[string]interface{} {\n        \"Application_Id\": \"YOUR_MOESIF_APPLICATION_ID\",\n        \"Log_Body\": true,\n}\nhttp.Handle(\"/api\", moesifmiddleware.MoesifMiddleware(http.HandlerFunc(handle), moesifOption))\n```\n\nReplace *`YOUR_MOESIF_APPLICATION_ID`* with [your Moesif Application ID](#get-your-moesif-application-id).\n\n### Optional: Capturing Outgoing API Calls\nIn addition to your own APIs, you can also start capturing calls out to third party services through the following method:\n\n```go\nmoesifmiddleware.StartCaptureOutgoing(moesifOption)\n```\n\n#### `handler func(ResponseWriter, *Request)` (Required)\n\nThe `handler` function registers the handler function for the given pattern through the `HandlerFunc` adapter. See the [example application code](https://github.com/Moesif/moesifmiddleware-go-example/blob/f3692a169ee0c7e73f109a54f65e28b55c611d01/main.go#L54) for better understanding.\n\n#### `moesifOption` (Required)\nA `map[string]interface{}` type containing the configuration options for your application. See [the example application code](https://github.com/Moesif/moesifmiddleware-go-example/blob/f3692a169ee0c7e73f109a54f65e28b55c611d01/moesif_options/moesif_options.go#L111) for better understanding.\n\nSee [Configuration Options](#configuration-options) for the common configuration options. See [Options for Logging Outgoing Calls](#options-for-logging-outgoing-calls) for configuration options specific to capturing and logging outgoing API calls.\n\n## Troubleshoot\nFor a general troubleshooting guide that can help you solve common problems, see [Server Troubleshooting Guide](https://www.moesif.com/docs/troubleshooting/server-troubleshooting-guide/). \n\nOther troubleshooting supports:\n\n- [FAQ](https://www.moesif.com/docs/faq/)\n- [Moesif support email](mailto:support@moesif.com)\n\n## Configuration Options\nThe following sections describe the available configuration options for this middleware. You can set these options in the Moesif initialization options object. See the the [example application code](https://github.com/Moesif/moesifmiddleware-go-example/blob/master/moesif_options/moesif_options.go) to understand how you can specify these options.\n\n### `Application_Id` (Required)\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA string that [identifies your application in Moesif](#get-your-moesif-application-id).\n\n### `Should_Skip`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eboolean\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that takes a request and a response,\nand returns `true` if you want to skip this particular event.\n\n### `Identify_User`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional, but highly recommended.\n\nA function that takes a request and a response, and returns a string that represents the user ID used by your system. \n\nMoesif identifies users automatically. However, due to the differences arising from different frameworks and implementations, provide this function to ensure user identification properly.\n\n### `Identify_Company`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional. \n\nA function that takes a request and response, and returns a string that represents the company ID for this event.\n\n### `Get_Metadata`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003edictionary\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that returns an object that allows you to add custom metadata that will be associated with the event. \n\nThe metadata must be a dictionary that can be converted to JSON. For example, you may want to save a virtual machine instance ID, a trace ID, or a tenant ID with the request.\n\n### `Get_Session_Token`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that takes a request and response, and returns a string that represents the session token for this event. \n\nSimilar to users and companies, Moesif tries to retrieve session tokens automatically. But if it doesn't work for your service, provide this function to help identify sessions.\n\n### `Request_Header_Masks`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e()\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e[]string\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that returns an array of strings to mask specific request header fields.\n\n### `Request_Body_Masks`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e()\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e[]string\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that returns array of strings to mask specific request body fields.\n\n### `Response_Header_Masks`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e()\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e[]string\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that returns array of strings to mask specific response header fields.\n\n### `Response_Body_Masks`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e()\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e[]string\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that returns array of strings to mask specific response body fields.\n\n### `Debug`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eboolean\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nSet to `true` to see debugging messages. This may help you troubleshoot integration issues.\n\n### `Log_Body`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eboolean\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003etrue\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nSet to `false` to not log the request and response body to Moesif.\n\n### `Event_Queue_Size`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eint\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e10000\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nAn optional field name that specifies the maximum number of events to hold in queue before sending to Moesif. In case of network issues, the middleware may fail to connect to or send events to Moesif. For those scenarios, this option helps prevent adding new events to the queue to prevent memory overflow.\n\n### `Batch_Size` \n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eint\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e200\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nAn optional field name that specifies the maximum batch size when sending to Moesif.\n\n### `Timer_Wake_Up_Seconds`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eint\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e2\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nAn optional field that specifies a time in seconds how often background thread runs to send events to Moesif.\n\n### Options for Logging Outgoing Calls\n\nThe following configuration options apply to outgoing API calls. The request and response objects passed in are [`Request`](https://golang.org/src/net/http/request.go) and [`Response`](https://golang.org/src/net/http/response.go) objects of the Go standard library.\n\n### `Should_Skip_Outgoing`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eboolean\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that takes a request and response, and returns `true` if you want to skip this particular event.\n\n### `Identify_User_Outgoing`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional, but highly recommended.\n\nA function that takes a request and a response, and returns a string that represents the user ID used by your system. \n\nMoesif identifies users automatically. However, due to the differences arising from different frameworks and implementations, provide this function to ensure user identification properly.\n\n### `Identify_Company_Outgoing`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that takes request and response, and returns a string that represents the company ID for this event.\n\n### `Get_Metadata_Outgoing`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003edictionary\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that returns an object that allows you to add custom metadata that will be associated with the event. \n\nThe metadata must be a dictionary that can be converted to JSON. For example, you may want to save a virtual machine instance ID, a trace ID, or a tenant ID with the request.\n\n### `Get_Session_Token_Outgoing`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(request, response)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003estring\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nA function that takes a request and response, and returns a string that represents the session token for this event. \n\nSimilar to users and companies, Moesif tries to retrieve session tokens automatically. But if it doesn't work for your service, provide this function to help identify sessions and replay them.\n\n### `Log_Body_Outgoing`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eboolean\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003etrue\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nOptional.\n\nSet to `false` to not log the request and response body to Moesif.\n\n## Examples\n\n- [Example Go app that using this middleware](https://github.com/Moesif/moesifmiddleware-go-example)\n- [Example Go app using this middleware and Google Cloud Run functions](https://github.com/Moesif/moesif-gcp-function-go-example)\n\nThe following examples demonstrate some common operations:\n\n- [Updating a single user](#updateuser-method)\n- [Updating users in batch](#updateusersbatch-method)\n- [Updating a single company](#updatecompany-method)\n- [Updating companies in batch](#updatecompaniesbatch-method)\n- [Updating a single subscription](#updatesubscription-method)\n- [Updating subscriptions in batch](#updatesubscriptionsbatch-method)\n\n## Update User\n\n### `UpdateUser` Method\nUse this method to create or update a user profile in Moesif.\n\n\n```go\nimport (\n\tmoesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc literalFieldValue(value string) *string {\n    return \u0026value\n}\n\nvar moesifOptions = map[string]interface{} {\n\t\"Application_Id\": \"Your Moesif Application Id\",\n\t\"Log_Body\": true,\n}\n\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#users for campaign schema\ncampaign := models.CampaignModel {\n  UtmSource: literalFieldValue(\"google\"),\n  UtmMedium: literalFieldValue(\"cpc\"), \n  UtmCampaign: literalFieldValue(\"adwords\"),\n  UtmTerm: literalFieldValue(\"api+tooling\"),\n  UtmContent: literalFieldValue(\"landing\"),\n}\n  \n// metadata can be any custom dictionary\nmetadata := map[string]interface{}{\n  \"email\": \"john@acmeinc.com\",\n  \"first_name\": \"John\",\n  \"last_name\": \"Doe\",\n  \"title\": \"Software Engineer\",\n  \"sales_info\": map[string]interface{}{\n      \"stage\": \"Customer\",\n      \"lifetime_value\": 24000,\n      \"account_owner\": \"mary@contoso.com\",\n  },\n}\n\n// Only UserId is required\nuser := models.UserModel{\n  UserId:  \"12345\",\n  CompanyId:  literalFieldValue(\"67890\"), // If set, associate user with a company object\n  Campaign:  \u0026campaign,\n  Metadata:  \u0026metadata,\n}\n\n// Update User\nmoesifmiddleware.UpdateUser(\u0026user, moesifOption)\n```\n\nThe `metadata` field can contain any user demographic or other information you want to store.\n\nOnly the `UserId` field is required.\nThis method is a convenient helper that calls the Moesif API library. For more information, see [Moesif Go API documentation](https://www.moesif.com/docs/api?go#update-a-user).\n\n### `UpdateUsersBatch` Method\nSimilar to `UpdateUser`, but to update a list of users in one batch. \n\n```go\n\nimport (\n\tmoesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc literalFieldValue(value string) *string {\n    return \u0026value\n}\n\nvar moesifOptions = map[string]interface{} {\n\t\"Application_Id\": \"Your Moesif Application Id\",\n}\n\n// List of Users\nvar users []*models.UserModel\n\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#users for campaign schema\ncampaign := models.CampaignModel {\n  UtmSource: literalFieldValue(\"google\"),\n  UtmMedium: literalFieldValue(\"cpc\"), \n  UtmCampaign: literalFieldValue(\"adwords\"),\n  UtmTerm: literalFieldValue(\"api+tooling\"),\n  UtmContent: literalFieldValue(\"landing\"),\n}\n  \n// metadata can be any custom dictionary\nmetadata := map[string]interface{}{\n  \"email\": \"john@acmeinc.com\",\n  \"first_name\": \"John\",\n  \"last_name\": \"Doe\",\n  \"title\": \"Software Engineer\",\n  \"sales_info\": map[string]interface{}{\n      \"stage\": \"Customer\",\n      \"lifetime_value\": 24000,\n      \"account_owner\": \"mary@contoso.com\",\n  },\n}\n\n// Only UserId is required\nuserA := models.UserModel{\n  UserId:  \"12345\",\n  CompanyId:  literalFieldValue(\"67890\"), // If set, associate user with a company object\n  Campaign:  \u0026campaign,\n  Metadata:  \u0026metadata,\n}\n\nusers = append(users, \u0026userA)\n\n// Update User\nmoesifmiddleware.UpdateUsersBatch(users, moesifOption)\n```\n\nThe `metadata` field can contain any company demographic or other information you want to store.\n\nOnly the `UserId` field is required.\nThis method is a convenient helper that calls the Moesif API library. For more information, see [Moesif Go API documentation](https://www.moesif.com/docs/api?go#update-users-in-batch)\n\n## Update Company\n\n### `UpdateCompany` Method\nUse this method to create or update a company profile in Moesif.\n\n```go\nimport (\n\tmoesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc literalFieldValue(value string) *string {\n    return \u0026value\n}\n\nvar moesifOptions = map[string]interface{} {\n\t\"Application_Id\": \"Your Moesif Application Id\",\n}\n\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#update-a-company for campaign schema\ncampaign := models.CampaignModel {\n  UtmSource: literalFieldValue(\"google\"),\n  UtmMedium: literalFieldValue(\"cpc\"), \n  UtmCampaign: literalFieldValue(\"adwords\"),\n  UtmTerm: literalFieldValue(\"api+tooling\"),\n  UtmContent: literalFieldValue(\"landing\"),\n}\n  \n// metadata can be any custom dictionary\nmetadata := map[string]interface{}{\n  \"org_name\": \"Acme, Inc\",\n  \"plan_name\": \"Free\",\n  \"deal_stage\": \"Lead\",\n  \"mrr\": 24000,\n  \"demographics\": map[string]interface{}{\n      \"alexa_ranking\": 500000,\n      \"employee_count\": 47,\n  },\n}\n\n// Prepare company model\ncompany := models.CompanyModel{\n\tCompanyId:\t\t  \"67890\",\t// The only required field is your company id\n\tCompanyDomain:  literalFieldValue(\"acmeinc.com\"), // If domain is set, Moesif will enrich your profiles with publicly available info \n\tCampaign: \t\t  \u0026campaign,\n\tMetadata:\t\t    \u0026metadata,\n}\n\n// Update Company\nmoesifmiddleware.UpdateCompany(\u0026company, moesifOption)\n```\n\nThe metadata field can be any company demographic or other info you want to store.\n\nOnly the `CompanyId` field is required.\n\nThis method is a convenient helper that calls the Moesif API library. For details, see [Moesif Go API documentation](https://www.moesif.com/docs/api?go#update-a-company).\n\n\n### `UpdateCompaniesBatch` Method\nSimilar to `UpdateCompany`, but to update a list of companies in one batch. \n\n```go\n\nimport (\n\tmoesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc literalFieldValue(value string) *string {\n    return \u0026value\n}\n\nvar moesifOptions = map[string]interface{} {\n\t\"Application_Id\": \"Your Moesif Application Id\",\n}\n\n// List of Companies\nvar companies []*models.CompanyModel\n\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#update-a-company for campaign schema\ncampaign := models.CampaignModel {\n  UtmSource: literalFieldValue(\"google\"),\n  UtmMedium: literalFieldValue(\"cpc\"), \n  UtmCampaign: literalFieldValue(\"adwords\"),\n  UtmTerm: literalFieldValue(\"api+tooling\"),\n  UtmContent: literalFieldValue(\"landing\"),\n}\n  \n// metadata can be any custom dictionary\nmetadata := map[string]interface{}{\n  \"org_name\": \"Acme, Inc\",\n  \"plan_name\": \"Free\",\n  \"deal_stage\": \"Lead\",\n  \"mrr\": 24000,\n  \"demographics\": map[string]interface{}{\n      \"alexa_ranking\": 500000,\n      \"employee_count\": 47,\n  },\n}\n\n// Prepare company model\ncompanyA := models.CompanyModel{\n\tCompanyId:\t\t  \"67890\",\t// The only required field is your company id\n\tCompanyDomain:  literalFieldValue(\"acmeinc.com\"), // If domain is set, Moesif will enrich your profiles with publicly available info \n\tCampaign: \t\t  \u0026campaign,\n\tMetadata:\t\t    \u0026metadata,\n}\n\ncompanies = append(companies, \u0026companyA)\n\n// Update Companies\nmoesifmiddleware.UpdateCompaniesBatch(companies, moesifOption)\n```\n\nThe metadata field can be any company demographic or other info you want to store.\n\nOnly the `CompanyId` field is required.\n\nThis method is a convenient helper that calls the Moesif API library. For details, see [Moesif Go API documentation](https://www.moesif.com/docs/api?go#update-companies-in-batch).\n\n## Update Subscription\n\n### `UpdateSubscription` Method\nUse this method to create or update a subscription profile in Moesif.\n \n```go\nimport (\n\tmoesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc literalFieldValue(value string) *string {\n    return \u0026value\n}\n\nvar moesifOptions = map[string]interface{} {\n\t\"Application_Id\": \"Your Moesif Application Id\",\n}\n\n// metadata can be any custom dictionary\nmetadata := map[string]interface{}{\n  \"plan_name\": \"Pro\",\n  \"deal_stage\": \"Customer\",\n  \"mrr\": 48000,\n  \"demographics\": map[string]interface{}{\n      \"subscription_length\": 12,\n      \"subscription_type\": \"annual\",\n  },\n}\n\n// Prepare subscription model\nsubscription := models.SubscriptionModel{\n\tSubscriptionId: \"12345\",\t// Required subscription id\n  CompanyId: \"67890\",       // Required company id\n\tMetadata: \u0026metadata,\n}\n\n// Update Subscription\nmoesifmiddleware.UpdateSubscription(\u0026subscription, moesifOptions)\n```\n\n\nThe `metadata` field can be any subscription demographic or other information you want to store.\n\nOnly the `SubscriptionId` and `CompanyId` fields are required.\n\nThis method is a convenient helper that calls the Moesif API library. For more information, see [Moesif Go API documentation](https://www.moesif.com/docs/api?go#update-a-subscription).\n\n\n### `UpdateSubscriptionsBatch` method\nSimilar to `UpdateSubscription`, but to update a list of subscriptions in one batch. \n\n```go\nimport (\n\tmoesifmiddleware \"github.com/moesif/moesifmiddleware-go\"\n)\n\nfunc literalFieldValue(value string) *string {\n    return \u0026value\n}\n\nvar moesifOptions = map[string]interface{} {\n\t\"Application_Id\": \"Your Moesif Application Id\",\n}\n\n// List of Subscriptions\nvar subscriptions []*models.SubscriptionModel\n\n// metadata can be any custom dictionary\nmetadata := map[string]interface{}{\n  \"plan_name\": \"Pro\",\n  \"deal_stage\": \"Customer\",\n  \"mrr\": 48000,\n  \"demographics\": map[string]interface{}{\n      \"subscription_length\": 12,\n      \"subscription_type\": \"annual\",\n  },\n}\n\n// Prepare subscription model\nsubscriptionA := models.SubscriptionModel{\n\tSubscriptionId: \"12345\",\t// Required subscription id\n  CompanyId: \"67890\",       // Required company id\n\tMetadata: \u0026metadata,\n}\n\nsubscriptions = append(subscriptions, \u0026subscriptionA)\n\n// Update Subscriptions\nmoesifmiddleware.UpdateSubscriptionsBatch(subscriptions, moesifOptions)\n```\n\nThe `metadata` field can be any subscription demographic or other information you want to store.\n\nOnly the `SubscriptionId` and `CompanyId` fields are required.\n\nThis method is a convenient helper that calls the Moesif API library. For more information, see [Moesif Go API documentation](https://www.moesif.com/docs/api?go#update-subscriptions-in-batch).\n\n## Explore Other Integrations\n\nExplore other integration options from Moesif:\n\n- [Server integration options documentation](https://www.moesif.com/docs/server-integration//)\n- [Client integration options documentation](https://www.moesif.com/docs/client-integration/)\n\n[ico-built-for]: https://img.shields.io/badge/built%20for-go-blue.svg\n[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg\n[ico-source]: https://img.shields.io/github/last-commit/moesif/moesifmiddleware-go.svg?style=social\n\n[link-built-for]: https://golang.org/\n[link-license]: https://raw.githubusercontent.com/Moesif/moesifmiddleware-go/master/LICENSE\n[link-source]: https://github.com/Moesif/moesifmiddleware-go\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoesif%2Fmoesifmiddleware-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoesif%2Fmoesifmiddleware-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoesif%2Fmoesifmiddleware-go/lists"}