{"id":24562522,"url":"https://github.com/davidleitw/gin-limiter","last_synced_at":"2025-04-19T17:42:41.704Z","repository":{"id":57540500,"uuid":"282039553","full_name":"davidleitw/gin-limiter","owner":"davidleitw","description":"A simple gin middleware for ip limiter based on redis.","archived":false,"fork":false,"pushed_at":"2023-06-01T20:17:03.000Z","size":75,"stargazers_count":31,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T11:01:29.225Z","etag":null,"topics":["gin","go","golang","ip-limit","limit","lua","middleware","redis","redis-client"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidleitw.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":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-23T19:36:15.000Z","updated_at":"2024-05-08T06:54:30.000Z","dependencies_parsed_at":"2024-06-20T04:23:59.717Z","dependency_job_id":"e5815e97-4c62-4c7e-96c0-99ed273edd91","html_url":"https://github.com/davidleitw/gin-limiter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidleitw%2Fgin-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidleitw%2Fgin-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidleitw%2Fgin-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidleitw%2Fgin-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidleitw","download_url":"https://codeload.github.com/davidleitw/gin-limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249751589,"owners_count":21320332,"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","go","golang","ip-limit","limit","lua","middleware","redis","redis-client"],"created_at":"2025-01-23T09:15:56.041Z","updated_at":"2025-04-19T17:42:41.661Z","avatar_url":"https://github.com/davidleitw.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003egin- limiter\u003c/h1\u003e\n\u003ch5 align=\"center\"\u003eA simple gin middleware for IP limiter based on redis.\u003c/h5\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.gnu.org/licenses/\"\u003e \n        \u003cimg src=\"https://img.shields.io/github/license/davidleitw/goGamer.svg\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://hits.dwyl.io/davidleitw/gin-limiter\"\u003e\n        \u003cimg src=http://hits.dwyl.io/davidleitw/gin-limiter.svg alt=\"HitCount\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/davidleitw/gin-limiter/stargazers\"\u003e \n        \u003cimg src=\"https://img.shields.io/github/stars/davidleitw/gin-limiter\" alt=\"GitHub stars\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n### Installation\n- Download\n\n    Type the following command in your terminal.\n    ```bash\n    go get github.com/go-redis/redis/v8\n    go get github.com/davidleitw/gin-limiter \n    ``` \n\n- Import\n    ```go \n    import \"github.com/go-redis/redis/v8\"\n    import limiter \"github.com/davidleitw/gin-limiter\"\n    ```\n\n---\n\n### Quickstart\n\n- Create a limit middleware dispatcher object\n    ```go\n    // Set redis client\n    rdb := redis.NewClient(\u0026redis.Options{Addr: \"localhost:6379\", Password: \"\", DB: 0})\n\n    dispatcher, err := limiter.LimitDispatcher(\"24-M\", 100, rdb)\n\n    if err != nil {\n        log.Println(err)\n    }\n\n    ```\n\n- Add a middleware to controlling each route. \n    ```go\n    server := gin.Default()\n\n    server.POST(\"/ExamplePost1\", dispatcher.MiddleWare(\"4-M\", 20), func(ctx *gin.Context) {\n\t\tctx.String(http.StatusOK, \"Hello ExamplePost1\")\n\t})\n\n\tserver.GET(\"/ExampleGet1\", dispatcher.MiddleWare(\"5-M\", 10), func(ctx *gin.Context) {\n\t\tctx.String(http.StatusOK, \"Hello ExampleGet1\")\n\t})\n\n\terr = server.Run(\":8080\")\n\tif err != nil {\n\t\tlog.Println(\"gin server error = \", err)\n\t}\n    ```\n\n\n    See more examples [HERE](https://github.com/davidleitw/gin-limiter/blob/master/Example). \n\n---\n\n### Response \n- When the total of request times is within limit, we will write data to header.\n    ```\n    Return header:\n\n    X-RateLimit-Limit-global     -\u003e Request limit of a single ip can send request for the server. \n    X-RateLimit-Remaining-global -\u003e Remaining times which single ip can send request for the server.\n    X-RateLimit-Reset-global     -\u003e Time to global limit reset. \n\n    X-RateLimit-Limit-single     -\u003e Request limit of a single ip can send request for the single route.\n    X-RateLimit-Remaining-single -\u003e Remaining times which single ip can send request for the single route.\n    X-RateLimit-Reset-single     -\u003e Time to single route limit reset. \n\n    ```\n\n- When global limit or single route limit is reached, a `429` HTTP status code is sent.\n    and add the header with:\n    ```shell\n    Return header:\n    \n    If global remaining request time \u003c 0\n        return global limit reset time. \n\n    If single remaining request time \u003c 0\n        return this single route limit reset time.\n    ```\n\n\u003chr\u003e\n\n### Reference\n- https://github.com/ulule/limiter\n- https://github.com/jpillora/ipfilter\n- https://github.com/KennyChenFight/dcard-simple-demo\n\n\u003chr\u003e\n\nIf you want to know the updated progress, please check `Ipfilter` branch. \n\n### License\n\nAll source code is licensed under the [MIT License](./LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidleitw%2Fgin-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidleitw%2Fgin-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidleitw%2Fgin-limiter/lists"}