{"id":20355921,"url":"https://github.com/hedzr/rate","last_synced_at":"2026-06-23T22:32:31.474Z","repository":{"id":57595741,"uuid":"374057491","full_name":"hedzr/rate","owner":"hedzr","description":"rate limit library in golang","archived":false,"fork":false,"pushed_at":"2023-06-07T09:38:09.000Z","size":74,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T17:41:04.097Z","etag":null,"topics":["cmdr","gin-middleware","rate-limit","rate-limiter","rate-limiting"],"latest_commit_sha":null,"homepage":"https://hedzr.com/golang/algorithm/rate-limit-1/","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/hedzr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":"supports/main.go","governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"custom":"https://paypal.me/hezr/3"}},"created_at":"2021-06-05T08:08:41.000Z","updated_at":"2023-06-07T01:56:05.000Z","dependencies_parsed_at":"2024-02-16T04:44:52.315Z","dependency_job_id":null,"html_url":"https://github.com/hedzr/rate","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/hedzr/rate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Frate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Frate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Frate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Frate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hedzr","download_url":"https://codeload.github.com/hedzr/rate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Frate/sbom","scorecard":{"id":459545,"data":{"date":"2025-08-11","repo":{"name":"github.com/hedzr/rate","commit":"887d9ff1844ba309d61d0c2b55840613a8bee74e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/20 approved changesets -- score normalized to 0","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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"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":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"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":"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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:97: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:101: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:104: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:241: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:248: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:63: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:70: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:82: update your workflow using https://app.stepsecurity.io/secureworkflow/hedzr/rate/go.yml/master?enable=pin","Info:   0 out of  10 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"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":"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":"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":"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":"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":8,"reason":"1 out of the last 1 releases have a total of 1 signed artifacts.","details":["Info: signed release artifact: binaries.asc: https://github.com/hedzr/rate/releases/tag/v0.5.0","Warn: release artifact v0.5.0 does not have provenance: https://api.github.com/repos/hedzr/rate/releases/92000519"],"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":"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":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 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-19T10:43:43.547Z","repository_id":57595741,"created_at":"2025-08-19T10:43:43.547Z","updated_at":"2025-08-19T10:43:43.547Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34709802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","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":["cmdr","gin-middleware","rate-limit","rate-limiter","rate-limiting"],"created_at":"2024-11-14T23:14:29.514Z","updated_at":"2026-06-23T22:32:31.459Z","avatar_url":"https://github.com/hedzr.png","language":"Go","funding_links":["https://paypal.me/hezr/3"],"categories":[],"sub_categories":[],"readme":"# go-rate\n\n![Go](https://github.com/hedzr/rate/workflows/Go/badge.svg)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/hedzr/rate.svg?label=release)](https://github.com/hedzr/rate/releases)\n[![](https://img.shields.io/badge/go-dev-green)](https://pkg.go.dev/github.com/hedzr/rate)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/hedzr/rate) \u003c!-- [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhedzr%2Frate.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhedzr%2Frate?ref=badge_shield) \n--\u003e [![Go Report Card](https://goreportcard.com/badge/github.com/hedzr/rate)](https://goreportcard.com/report/github.com/hedzr/rate)\n[![Coverage Status](https://coveralls.io/repos/github/hedzr/rate/badge.svg?branch=master\u0026.9)](https://coveralls.io/github/hedzr/rate?branch=master)\n\n`go-rate` provides the rate limiters generally.\n\n## Features\n\n## History\n\n- v0.5.0\n  - BREAK: To decrease unecessary dependants, we removed `middleware` subpackage. It has been moved into `supports/` and taged with `ignore`.\n    - You must copy its codes to use it.\n  - the codes reviewed\n  - no any third-party deps now, even from mine.\n\n- v0.1.x\n  - as is\n\n## Usages\n\n### Simple\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/hedzr/rate\"\n\t\"time\"\n)\n\nfunc main() {\n\tl := rate.New(rate.LeakyBucket, 100, time.Second)\n\tfor i := 0; i \u003c 120; i++ {\n\t\tok := l.Take(1)\n\t\tif !ok {\n\t\t\tfmt.Printf(\"#%d Take() returns not ok, counter: %v\\n\", i, rate.CountOf(l))\n\t\t\ttime.Sleep(50 * time.Millisecond)\n\t\t}\n\t}\n}\n```\n\n### As a gin middleware\n\n```go\npackage main\n\nimport (\n   \"github.com/gin-gonic/gin\"\n   \"github.com/hedzr/rate\"\n   \"github.com/hedzr/rate/middleware\"\n   \"time\"\n)\n\nfunc webserver() {\n\tr := engine()\n\tr.Run(\":3000\")\n}\n\nfunc engine() *gin.Engine {\n\tconfig := \u0026middleware.Config{\n\t\tName:          \"...\",\n\t\tDescription:   \"...\",\n\t\tAlgorithm:     string(rate.TokenBucket),\n\t\tInterval:      time.Second,\n\t\tMaxRequests:   1000,\n\t\tHeaderKeyName: \"X-API-TOKEN\",\n\t\tExceptionKeys: nil,\n\t\tRoutes:        nil,\n\t}\n\tr := gin.Default()\n\tr.Use(middleware.ForGin(config))\n\treturn r\n}\n```\n\n### Load limit config with cmdr Option Store\n\nWhile integrated with [hedzr/cmdr](https://github.com/hedzr/cmdr), the short loading is available:\n\n```go\nimport \"github.com/hedzr/rate/middleware\"\n\nfunc BuildRoutes(rg *gin.Engine) *gin.Engine {\n    buildRoutes(rg.Group(\"/prefix\"), rg)\n}\nfunc buildRoutes(rg Router, root *gin.Engine) {\n    middleware.LoadConfigForGin(\"server.rate-limits\", rg)\n    rg.Get(\"/echo/*action\", echoHandler)\n}\nfunc echoGinHandler(c *gin.Context) {\n    action := c.Param(\"action\")\n    if action == \"\" || action == \"/\" {\n        action = \"\u003cno action\u003e\"\n    }\n    _, _ = io.WriteString(c.Writer, fmt.Sprintf(\"action: %v\\n\", action))\n}\n```\n\nA config file (eg. `rate-limit.yml`) should be put in cmdr-standard `conf.d` directory, so it can be loaded automatically:\n\n```yaml\napp:\n  your-app: # \u003c- replace it with your app name, the further KB in cmdr docs.\n    server:\n      rate-limits:\n        - name: by-api-key\n          interval: 1ms\n          max-requests: 30\n          header-key-name: X-API-KEY\n          exception-keys: [voxr-apps-test-api-key-fndsfjn]\n```\n\n\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedzr%2Frate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhedzr%2Frate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedzr%2Frate/lists"}