{"id":25184582,"url":"https://github.com/xuender/limit","last_synced_at":"2026-05-17T00:03:33.352Z","repository":{"id":64300036,"uuid":"570012114","full_name":"xuender/limit","owner":"xuender","description":"A Go rate limit implementation","archived":false,"fork":false,"pushed_at":"2024-08-05T09:02:01.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-09T19:40:50.650Z","etag":null,"topics":["go","golang","limit","limiter","middleware","rate-limit","redis"],"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/xuender.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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":"2022-11-24T06:12:03.000Z","updated_at":"2024-08-05T09:02:01.000Z","dependencies_parsed_at":"2025-02-09T19:43:22.522Z","dependency_job_id":null,"html_url":"https://github.com/xuender/limit","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuender%2Flimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuender%2Flimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuender%2Flimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuender%2Flimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xuender","download_url":"https://codeload.github.com/xuender/limit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247148980,"owners_count":20891948,"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":["go","golang","limit","limiter","middleware","rate-limit","redis"],"created_at":"2025-02-09T19:33:17.291Z","updated_at":"2025-10-14T07:03:57.947Z","avatar_url":"https://github.com/xuender.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Limit\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/xuender/limit)](https://goreportcard.com/report/github.com/xuender/limit)\n[![tag](https://img.shields.io/github/tag/xuender/limit.svg)](https://github.com/xuender/limit/releases)\n![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.18-%23007d9c)\n[![GoDoc](https://godoc.org/github.com/xuender/limit?status.svg)](https://pkg.go.dev/github.com/xuender/limit)\n![Build Status](https://github.com/xuender/limit/actions/workflows/go.yml/badge.svg)\n[![Coverage](https://img.shields.io/codecov/c/github/xuender/limit)](https://codecov.io/gh/xuender/limit)\n[![License](https://img.shields.io/github/license/xuender/limit)](./LICENSE)\n\nGolang channel based rate limiter.\n\n* supports asynchronous and synchronous calls.\n* simple middleware to rate limit HTTP requests.\n* requests that may timeout will returns an error immediately.\n* call order.\n* redis based distributed limiter.\n\n## 💡 Usage\n\nYou can import limit using:\n\n```go\nimport \"github.com/xuender/limit\"\n```\n\n### Async\n\n```go\nstart := time.Now()\nlimiter := limit.NewAsync(10, time.Second, func(num int) {\n  fmt.Println(time.Since(start), num)\n})\n\n_ = limiter.Add(1)\n_ = limiter.Add(2)\n_ = limiter.Add(3)\n\ntime.Sleep(time.Second)\n\n// Output:\n// 100ms 1\n// 200ms 2\n// 300ms 3\n```\n\n[[play](https://go.dev/play/p/W9gYA_109Vz)]\n\n### Sync\n\n```go\nstart := time.Now()\nlimiter := limit.NewSync(10, time.Second)\n\n_ = limiter.Wait()\n_ = limiter.Wait()\n_ = limiter.Wait()\n\nfmt.Println(time.Since(start))\n\n// Output:\n// 300ms\n```\n\n[[play](https://go.dev/play/p/ogcvT7o4ENI)]\n\n### rdb.Distributed\n\nredis based distributed limiter.\n\n```go\nclient := redis.NewClient(\u0026redis.Options{\n  Addr:     \"localhost:6379\",\n  Password: \"\",\n  DB:       0,\n})\nstart := time.Now()\nlimiter := rdb.NewDistributed(client, \"key\", 1000, time.Second)\n\n_ = limiter.Wait()\n_ = limiter.Wait()\n_ = limiter.Wait()\n\nfmt.Println(time.Since(start))\n```\n\n[[play]](https://go.dev/play/p/SgAqdQRYhiK)\n\n### Handler\n\n```go\nhttp.Handle(\"/\", limit.FuncHandler(1000, time.Second*10,\n  func(w http.ResponseWriter, r *http.Request) {\n    _, _ = io.WriteString(w, \"PONG\")\n  },\n))\nhttp.ListenAndServe(\":8080\", nil)\n```\n\n[[play](https://go.dev/play/p/oAoIZynIdkn)]\n\n## 😁 Cover\n\n![codecov](https://codecov.io/gh/xuender/limit/branch/main/graphs/tree.svg?token=CDCXOD9XYO)\n\n## 📝 License\n\n© ender, 2022~time.Now\n\n[MIT License](https://github.com/xuender/limit/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuender%2Flimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuender%2Flimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuender%2Flimit/lists"}