{"id":20170216,"url":"https://github.com/alexrios/lbucket","last_synced_at":"2025-04-10T02:26:23.765Z","repository":{"id":57588402,"uuid":"372293143","full_name":"alexrios/lbucket","owner":"alexrios","description":"An idiomatic Go implementation of Leaky bucket.","archived":false,"fork":false,"pushed_at":"2021-05-31T20:43:27.000Z","size":6,"stargazers_count":11,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T06:12:04.815Z","etag":null,"topics":["golang","idiomatic","leaky-bucket"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/alexrios/lbucket?tab=doc","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/alexrios.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-05-30T18:56:17.000Z","updated_at":"2022-04-17T13:53:06.000Z","dependencies_parsed_at":"2022-09-26T19:42:48.993Z","dependency_job_id":null,"html_url":"https://github.com/alexrios/lbucket","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/alexrios%2Flbucket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrios%2Flbucket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrios%2Flbucket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrios%2Flbucket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexrios","download_url":"https://codeload.github.com/alexrios/lbucket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143703,"owners_count":21054826,"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":["golang","idiomatic","leaky-bucket"],"created_at":"2024-11-14T01:17:43.914Z","updated_at":"2025-04-10T02:26:23.741Z","avatar_url":"https://github.com/alexrios.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lbucket\n[![Go Reference](https://pkg.go.dev/badge/github.com/alexrios/lbucket.svg)](https://pkg.go.dev/github.com/alexrios/lbucket?tab=doc)\n\nlbucket is an idiomatic Go leaky bucket implementation.\n\nThe library make use of plain old Go stdlib; in other words, there are no third-party dependencies.\n\n### How to use\nPackage lbucket provides support for using leaky buckets on your app.\n\nCreating a new Leaky bucket informing 3 as the bucket capacity and the frequency how the bucket leaks.\n```go\nNewTickLeakyBucket(3, 1 * time.Second)\n```\n\nCalling `Refill()` you're add more volume in the bucket.\n```go\nbucket := NewTickLeakyBucket(3, 1 * time.Second)\nerr := bucket.Refill()\n```\nNote: When the bucket capacity is reached a `ErrBucketReachedCap` will be returned until the bucket leaks once again.\nA simple `errors.Is` could be used in this scenario:\n```go\nerrors.Is(err, ErrBucketReachedCap)\n```\n\nTo stop the bucket leaking you can call the `Fix()` method.\n```go\nbucket.Fix()\n```\n\nUse Size() to get to current volume in the bucket.\n```go\nbucket.Size()\n```\n\n### Common use case(s)\n#### API's rate limiter. \n  \nIn this use you can read:\n- NewTickLeakyBucket() as `How many requests per second it's gonna handle?`\n- Refill() as `Can I respond this request?`\n    - ErrBucketReachedCap as `Reched the server limit`\n- Fix() as `From now on I'm no longer accepting requests`\n- Size() as `How many requests are in flight?`\n\neg: `NewTickLeakyBucket(3, 1 * time.Second)` -\u003e 3 requests / second.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexrios%2Flbucket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexrios%2Flbucket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexrios%2Flbucket/lists"}