{"id":18822742,"url":"https://github.com/varthanv/gin-idempotency","last_synced_at":"2026-03-16T09:37:48.555Z","repository":{"id":65695933,"uuid":"597439063","full_name":"VarthanV/gin-idempotency","owner":"VarthanV","description":"An idempotency key middleware for Go gin framework with pluggable configurations","archived":false,"fork":false,"pushed_at":"2023-02-05T03:00:48.000Z","size":15,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T01:12:50.514Z","etag":null,"topics":["gin","golang","idempotency","middleware"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VarthanV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-04T14:59:22.000Z","updated_at":"2023-10-25T11:28:51.000Z","dependencies_parsed_at":"2023-02-18T18:15:56.565Z","dependency_job_id":null,"html_url":"https://github.com/VarthanV/gin-idempotency","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VarthanV%2Fgin-idempotency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VarthanV%2Fgin-idempotency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VarthanV%2Fgin-idempotency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VarthanV%2Fgin-idempotency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VarthanV","download_url":"https://codeload.github.com/VarthanV/gin-idempotency/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804825,"owners_count":21164135,"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":["gin","golang","idempotency","middleware"],"created_at":"2024-11-08T00:51:26.879Z","updated_at":"2026-03-16T09:37:48.527Z","avatar_url":"https://github.com/VarthanV.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-idempotency\n\n\n## Introduction\ngin-idempotency is a middleware for the [Gin](https://gin-gonic.com/) webframework. It checks whether the Idempotency key is passed in the headers\n\n\nAn idempotency key is a unique value generated by you. Our servers use this key to recognize subsequent retries of the same request. \n\nIt is used in places where we need to prevent the impact recognize subsequent retries of the same request. It is mainly used in payment/transaction API's. More about idempotency\n\n- [Stripe Reference](http://bit.ly/3WYB3Wc)\n- [Razorpay Reference](http://bit.ly/3latbDV)\n\n## Usage\n\nDownload and install it using go get\n\n```\ngo get github.com/VarthanV/gin-idempotency\n```\n\nImport it in your code\n\n```golang\nimport \"github.com/VarthanV/gin-idempotency\"\n\n```\n\n## Examples\n\n**using default config**\n\n```golang\npackage main\n\nimport (\n  \"github.com/Varthan/idempotency\"\n  \"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n  r := gin.Default()\n  r.Use(idempotency.New(idempotency.Default()))\n\n  r.POST(\"/transfer\", func(c *gin.Context) {\n    var existingIdempotentKey = \"foo\"\n    // The value in the header will parsed and will be set in the context with the following key name by default \n    var idempotencyKeyFromCtx = c.GetString(\"IdempotencyKey\")\n    if idempotencyKeyFromCtx == existingIdempotentKey { \n        c.JSON(403, gin.H{\"message\":\"send an new idempotency key\"})\n        return\n    }\n  })\n  r.Run(\":8000\")\n}\n```\n\n**using custom config**\n\n```golang\npackage main\n\nimport (\n  \"github.com/Varthan/idempotency\"\n  \"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n  r := gin.Default()\n  r.Use(idempotency.New(idempotency.IdempotencyConfig{\n    /* The middleware by default looks for the header with the key name  ``Idempotency-Key``*/\n    HeaderName: \"foo\" ,\n\n    /* The value in the header will parsed and will be set in the context with the  key name IdempotencyKey in the gin context by default, You can customise it based on your needs by the ContextKeyName param */\n    ContextKeyName: \"foo-ctx\" ,\n\n    /*\n    The httpStatusCode which you want to return incase the idempotencykey is not present default is 403\n    */\n    StatusCode: 418 ,\n    /* \n    Response payload which you want to send to the client when the key is not present. Default response is {\"error\":\"${{HeaderName}} is missing\"}\n    */\n    Response: map[string]string{\"message\":\"idempotency-key-doesnt-exist\"},\n    /* \n     Whitelist certain HTTP methods based on your needs\n    */\n    WhitelistHTTPMethods: []string{\"GET\"}\n    \n  }))\n\n  r.POST(\"/fund-transfer\", func(c *gin.Context) {\n    var existingIdempotentKey = \"foo\"\n    // The value in the header will parsed and will be set in the context with the following key name by default \n    var idempotencyKeyFromCtx = c.GetString(\"IdempotencyKey\")\n    if idempotencyKeyFromCtx == existingIdempotentKey { \n        c.JSON(403, gin.H{\"message\":\"send an new idempotency key\"})\n        return\n    }\n  })\n  r.Run(\":8000\")\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvarthanv%2Fgin-idempotency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvarthanv%2Fgin-idempotency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvarthanv%2Fgin-idempotency/lists"}