{"id":24838820,"url":"https://github.com/pixelbend/surgelimit-go","last_synced_at":"2025-03-26T04:30:18.695Z","repository":{"id":250585634,"uuid":"834863708","full_name":"pixelbend/surgelimit-go","owner":"pixelbend","description":"A flexible rate limiting package for Go.","archived":false,"fork":false,"pushed_at":"2025-02-24T00:24:56.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T01:25:10.693Z","etag":null,"topics":["consistent","distributed","dragonfly","go","keydb","kvrocks","leaky-bucket","rate-limiter","redis","redis-cluster","resilient","valkey"],"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/pixelbend.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":"2024-07-28T15:38:58.000Z","updated_at":"2025-02-24T00:24:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3fd086f-dccc-4107-ad97-6b39d5dd3f14","html_url":"https://github.com/pixelbend/surgelimit-go","commit_stats":null,"previous_names":["driftdev/zenlimiter","driftdev/surgelimit","driftdev/surgelimit-go","driftdev/zenlimit","codefrantic/surgelimit-go","pixelbend/surgelimit-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fsurgelimit-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fsurgelimit-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fsurgelimit-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Fsurgelimit-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixelbend","download_url":"https://codeload.github.com/pixelbend/surgelimit-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245589065,"owners_count":20640217,"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":["consistent","distributed","dragonfly","go","keydb","kvrocks","leaky-bucket","rate-limiter","redis","redis-cluster","resilient","valkey"],"created_at":"2025-01-31T06:35:45.891Z","updated_at":"2025-03-26T04:30:18.676Z","avatar_url":"https://github.com/pixelbend.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SurgeLimit Go\n\nSurgeLimit Go is a flexible and efficient rate limiting package for Go, designed to work with a variety of caching systems, including Redis, RedisCluster, ValKey, KeyDB, DragonflyDB, and Kvrocks. It implements a leaky bucket algorithm to help you control the rate of requests and manage traffic surges effectively.\n\n## Features\n\n- **Leaky Bucket Algorithm**: Implements the leaky bucket rate limiting algorithm, which smooths out bursts of traffic by allowing a fixed rate of requests and handling excess traffic gracefully.\n\n- **Multi-System Support**: Compatible with multiple Redis compatible systems, providing flexibility to integrate with your existing infrastructure.\n\n- **High Performance**: Designed for high performance and low latency, making it suitable for high-throughput applications.\n\n- **Configurable Limits**: Easily configure rate limits based on your application's needs, including maximum request rates and burst capacities.\n\n- **Redis Integration**: Fully integrated with popular Redis-based systems, offering robust support for distributed environments.\n\n## Installation\n\nTo install SurgeLimit Go, use the following command.\n\n```bash\ngo get github.com/pixelbend/surgelimit-go\n```\n\n## Usage\n\nHere's a basic example of how to use SurgeLimit Go.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/pixelbend/surgelimit-go/leakybucket\"\n\t\"github.com/go-redis/redis/v9\"\n)\n\nfunc main() {\n\t// Initialize Redis client\n\trdb := redis.NewClient(\u0026redis.Options{\n\t\tAddr:     \"localhost:6379\", \n\t\tPassword: \"\",               \n\t\tDB:       0,                \n\t})\n\n\t// Flush the Redis database to start with a clean state\n\tif err := rdb.FlushDB(context.Background()).Err(); err != nil {\n\t\tlog.Fatalf(\"Error flushing DB: %v\", err)\n\t}\n\n\t// Create a new leaky bucket rate limiter with default options\n\tlimiter := leakybucket.NewLimiter(rdb, leakybucket.DefaultOptions())\n\n\t// Attempt to allow a request under the rate limit\n\tres, err := limiter.Allow(context.Background(), \"project:01J61AAPTXV3HQD95XQWATPBS8\", leakybucket.LimitPerSecond(10))\n\tif err != nil {\n\t\tlog.Fatalf(\"Error checking rate limit: %v\", err)\n\t}\n\n\t// Check if the request is allowed\n\tif res.Allowed \u003e 0 {\n\t\t// If allowed, proceed with the application logic\n\t\tlog.Println(\"Request allowed, proceeding with application logic...\")\n\t} else {\n\t\t// If not allowed, handle the rate limit exceeded case\n\t\tlog.Println(\"Request denied: rate limit exceeded\")\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbend%2Fsurgelimit-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixelbend%2Fsurgelimit-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbend%2Fsurgelimit-go/lists"}