{"id":18821605,"url":"https://github.com/octu0/priorate","last_synced_at":"2026-01-18T09:30:18.407Z","repository":{"id":45584500,"uuid":"513818438","full_name":"octu0/priorate","owner":"octu0","description":"rate limiter with priority","archived":false,"fork":false,"pushed_at":"2024-11-18T05:34:23.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-12-30T03:43:12.583Z","etag":null,"topics":["go","golang","priority-scheduling","rate-limiting"],"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/octu0.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":"2022-07-14T08:23:31.000Z","updated_at":"2024-11-18T05:33:42.000Z","dependencies_parsed_at":"2022-09-26T21:30:44.177Z","dependency_job_id":null,"html_url":"https://github.com/octu0/priorate","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/octu0%2Fpriorate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fpriorate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fpriorate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fpriorate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/octu0","download_url":"https://codeload.github.com/octu0/priorate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239758900,"owners_count":19692041,"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","priority-scheduling","rate-limiting"],"created_at":"2024-11-08T00:44:51.887Z","updated_at":"2026-01-18T09:30:18.347Z","avatar_url":"https://github.com/octu0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `priorate`\n\n[![Apache License](https://img.shields.io/github/license/octu0/priorate)](https://github.com/octu0/priorate/blob/master/LICENSE)\n[![GoDoc](https://godoc.org/github.com/octu0/priorate?status.svg)](https://godoc.org/github.com/octu0/priorate)\n[![Go Report Card](https://goreportcard.com/badge/github.com/octu0/priorate)](https://goreportcard.com/report/github.com/octu0/priorate)\n[![Releases](https://img.shields.io/github/v/release/octu0/priorate)](https://github.com/octu0/priorate/releases)\n\n`priorate` provides rate limiter with priority using [golang.org/x/time/rate](https://pkg.go.dev/golang.org/x/time/rate).  \nPriority can be defined as a ratio from 0.01 to 0.99, and rate limit can be performed according to priority on a given limit.  \nFairly gets limit according to priority.\n\n## Installation\n\n```bash\ngo get github.com/octu0/priorate\n```\n\n## Example\n\nHere's a quick example for using `priorate.NewLimiter`.\n\n```go\nimport(\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/octu0/priorate\"\n)\n\nfunc main() {\n\tlimit := priorate.NewLimiter(100,\n\t\tpriorate.Priority(priorate.High, 0.7),\n\t\tpriorate.Priority(priorate.Low, 0.3),\n\t)\n\tfor i := 0; i \u003c 10; i += 1 {\n\t\tif i \u003c 5 {\n\t\t\thigh := limit.ReserveN(priorate.High, time.Now(), 30)\n\t\t\tprintDelay(high.Delay())\n\t\t} else {\n\t\t\tlow := limit.ReserveN(priorate.Low, time.Now(), 30)\n\t\t\tprintDelay(low.Delay())\n\t\t}\n\t}\n\n\t// Output:\n\t// 0s\n\t// 0s\n\t// 299ms\n\t// 1.099s\n\t// 1.899s\n\t// 1.199s\n\t// 1.966s\n\t// 3.233s\n\t// 4.499s\n\t// 5.766s\n}\n\nfunc printDelay(d time.Duration) {\n\tfmt.Println(d.Truncate(time.Millisecond))\n}\n```\n\n## License\n\nMIT, see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fpriorate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctu0%2Fpriorate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fpriorate/lists"}