{"id":23129039,"url":"https://github.com/twiny/limiter","last_synced_at":"2025-04-04T06:25:33.286Z","repository":{"id":57623013,"uuid":"395586047","full_name":"twiny/limiter","owner":"twiny","description":"IP based rate limiter","archived":false,"fork":false,"pushed_at":"2021-08-23T21:40:15.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T17:42:34.728Z","etag":null,"topics":["go","golang","http","limiter","rate-limiter","rest-api"],"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/twiny.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}},"created_at":"2021-08-13T09:04:09.000Z","updated_at":"2024-11-04T10:44:24.000Z","dependencies_parsed_at":"2022-08-26T23:51:39.717Z","dependency_job_id":null,"html_url":"https://github.com/twiny/limiter","commit_stats":null,"previous_names":["issmeftah/limiter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiny%2Flimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiny%2Flimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiny%2Flimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiny%2Flimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twiny","download_url":"https://codeload.github.com/twiny/limiter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247130938,"owners_count":20888683,"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","http","limiter","rate-limiter","rest-api"],"created_at":"2024-12-17T10:08:09.618Z","updated_at":"2025-04-04T06:25:33.258Z","avatar_url":"https://github.com/twiny.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## HTTP Rate Limiter\nrate limit HTTP requests based on client IP address.\n\n### Install\n`go get github.com/twiny/limiter`\n\n### Example\n\n```go\n\nimport \"github.com/twiny/limiter\"\n\n// App\ntype App struct{\n    ... ...\n    limiter *limiter.Limiter\n    ... ...\n}\n\n// RateLimit\nfunc (a *App) RateAllow(ip string) bool {\n\tlimit, found := a.limiter.Get(ip)\n\tif !found {\n\t\ta.limiter.Set(ip)\n\t\treturn true\n\t}\n\n\treturn limit.Allow()\n}\n```\n\n```go\n// HTTPHandler\ntype HTTPHandler struct{\n    ... ...\n    app *App\n    ... ...\n}\n\n// rate limit\nfunc (route *HTTPHandler) ratelimit(h http.Handler) http.Handler {\n\tfn := func(w http.ResponseWriter, r *http.Request) {\n\t\tvar remoteIP string\n\t\tremoteIP = r.RemoteAddr\n\t\tif strings.ContainsRune(r.RemoteAddr, ':') {\n\t\t\tremoteIP, _, _ = net.SplitHostPort(r.RemoteAddr)\n\t\t}\n\n\t\tif !route.app.RateAllow(remoteIP) {\n\t\t\thttp.Error(w,\"going too fast - slow down\", http.StatusTooManyRequests)\n\t\t\treturn\n\t\t}\n\n\t\th.ServeHTTP(w, r)\n\t}\n\treturn http.HandlerFunc(fn)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwiny%2Flimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwiny%2Flimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwiny%2Flimiter/lists"}