{"id":13694381,"url":"https://github.com/beefsack/go-rate","last_synced_at":"2025-09-16T21:05:02.653Z","repository":{"id":20034041,"uuid":"23302143","full_name":"beefsack/go-rate","owner":"beefsack","description":"A timed rate limiter for Go","archived":false,"fork":false,"pushed_at":"2022-02-14T23:34:05.000Z","size":27,"stargazers_count":400,"open_issues_count":0,"forks_count":35,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-03T01:46:55.663Z","etag":null,"topics":[],"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/beefsack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"beefsack"}},"created_at":"2014-08-25T04:42:34.000Z","updated_at":"2025-03-17T17:15:21.000Z","dependencies_parsed_at":"2022-07-23T14:32:25.859Z","dependency_job_id":null,"html_url":"https://github.com/beefsack/go-rate","commit_stats":null,"previous_names":["beefsack/go-rate-limiter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beefsack/go-rate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beefsack%2Fgo-rate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beefsack%2Fgo-rate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beefsack%2Fgo-rate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beefsack%2Fgo-rate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beefsack","download_url":"https://codeload.github.com/beefsack/go-rate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beefsack%2Fgo-rate/sbom","scorecard":{"id":230125,"data":{"date":"2025-08-11","repo":{"name":"github.com/beefsack/go-rate","commit":"116f4ca011a0d87f476544896875e514767b2071"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":2,"reason":"Found 6/29 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 7 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T04:42:11.676Z","repository_id":20034041,"created_at":"2025-08-17T04:42:11.677Z","updated_at":"2025-08-17T04:42:11.677Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275483902,"owners_count":25473148,"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","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-08-02T17:01:30.568Z","updated_at":"2025-09-16T21:05:02.606Z","avatar_url":"https://github.com/beefsack.png","language":"Go","funding_links":["https://github.com/sponsors/beefsack"],"categories":["工具库","开源类库","Utilities","Open source library","实用工具","Utility","公用事业公司","工具库`可以提升效率的通用代码库和工具`","Go"],"sub_categories":["查询语","限流器","Utility/Miscellaneous","Advanced Console UIs","Current Limiter","HTTP Clients","交流","实用程序/Miscellaneous","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Fail injection"],"readme":"go-rate\n===============\n\n[![Build Status](https://travis-ci.org/beefsack/go-rate.svg?branch=master)](https://travis-ci.org/beefsack/go-rate)\n[![GoDoc](https://godoc.org/github.com/beefsack/go-rate?status.svg)](https://godoc.org/github.com/beefsack/go-rate)\n\n**go-rate** is a rate limiter designed for a range of use cases,\nincluding server side spam protection and preventing saturation of APIs you\nconsume.\n\nIt is used in production at\n[LangTrend](http://langtrend.com/l/Java,PHP,JavaScript) to adhere to the GitHub\nAPI rate limits.\n\nUsage\n-----\n\nImport `github.com/beefsack/go-rate` and create a new rate limiter with\nthe `rate.New(limit int, interval time.Duration)` function.\n\nThe rate limiter provides a `Wait()` and a `Try() (bool, time.Duration)` method\nfor both blocking and non-blocking functionality respectively.\n\nAPI documentation available at [godoc.org](http://godoc.org/github.com/beefsack/go-rate).\n\nExamples\n--------\n\n### Blocking rate limiting\n\nThis example demonstrates limiting the output rate to 3 times per second.\n\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/beefsack/go-rate\"\n)\n\nfunc main() {\n\trl := rate.New(3, time.Second) // 3 times per second\n\tbegin := time.Now()\n\tfor i := 1; i \u003c= 10; i++ {\n\t\trl.Wait()\n\t\tfmt.Printf(\"%d started at %s\\n\", i, time.Now().Sub(begin))\n\t}\n\t// Output:\n\t// 1 started at 12.584us\n\t// 2 started at 40.13us\n\t// 3 started at 44.92us\n\t// 4 started at 1.000125362s\n\t// 5 started at 1.000143066s\n\t// 6 started at 1.000144707s\n\t// 7 started at 2.000224641s\n\t// 8 started at 2.000240751s\n\t// 9 started at 2.00024244s\n\t// 10 started at 3.000314332s\n}\n```\n\n### Blocking rate limiting with multiple limiters\n\nThis example demonstrates combining rate limiters, one limiting at once per\nsecond, the other limiting at 2 times per 3 seconds.\n\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/beefsack/go-rate\"\n)\n\nfunc main() {\n\tbegin := time.Now()\n\trl1 := rate.New(1, time.Second)   // Once per second\n\trl2 := rate.New(2, time.Second*3) // 2 times per 3 seconds\n\tfor i := 1; i \u003c= 10; i++ {\n\t\trl1.Wait()\n\t\trl2.Wait()\n\t\tfmt.Printf(\"%d started at %s\\n\", i, time.Now().Sub(begin))\n\t}\n\t// Output:\n\t// 1 started at 11.197us\n\t// 2 started at 1.00011941s\n\t// 3 started at 3.000105858s\n\t// 4 started at 4.000210639s\n\t// 5 started at 6.000189578s\n\t// 6 started at 7.000289992s\n\t// 7 started at 9.000289942s\n\t// 8 started at 10.00038286s\n\t// 9 started at 12.000386821s\n\t// 10 started at 13.000465465s\n}\n```\n\n### Non-blocking rate limiting\n\nThis example demonstrates non-blocking rate limiting, such as would be used to\nlimit spam in a chat client.\n\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/beefsack/go-rate\"\n)\n\nvar rl = rate.New(3, time.Second) // 3 times per second\n\nfunc say(message string) {\n\tif ok, remaining := rl.Try(); ok {\n\t\tfmt.Printf(\"You said: %s\\n\", message)\n\t} else {\n\t\tfmt.Printf(\"Spam filter triggered, please wait %s\\n\", remaining)\n\t}\n}\n\nfunc main() {\n\tfor i := 1; i \u003c= 5; i++ {\n\t\tsay(fmt.Sprintf(\"Message %d\", i))\n\t}\n\ttime.Sleep(time.Second / 2)\n\tsay(\"I waited half a second, is that enough?\")\n\ttime.Sleep(time.Second / 2)\n\tsay(\"Okay, I waited a second.\")\n\t// Output:\n\t// You said: Message 1\n\t// You said: Message 2\n\t// You said: Message 3\n\t// Spam filter triggered, please wait 999.980816ms\n\t// Spam filter triggered, please wait 999.976704ms\n\t// Spam filter triggered, please wait 499.844795ms\n\t// You said: Okay, I waited a second.\n}\n```\n\nAuthors\n-------\n\n* [Michael Alexander](https://github.com/beefsack)\n* [Geert-Johan Riemer](https://github.com/GeertJohan)\n* [Matt T. Proud](https://github.com/matttproud)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeefsack%2Fgo-rate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeefsack%2Fgo-rate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeefsack%2Fgo-rate/lists"}