{"id":36667854,"url":"https://github.com/pacedotdev/batch","last_synced_at":"2026-01-12T10:37:05.496Z","repository":{"id":57515760,"uuid":"224643668","full_name":"pacedotdev/batch","owner":"pacedotdev","description":"Very simple batching API for Go.","archived":false,"fork":false,"pushed_at":"2021-10-22T05:16:51.000Z","size":10,"stargazers_count":90,"open_issues_count":5,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-06-19T02:09:35.107Z","etag":null,"topics":["golang"],"latest_commit_sha":null,"homepage":"https://pace.dev/blog/2020/02/13/batching-operations-in-go-by-mat-ryer","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/pacedotdev.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":"2019-11-28T11:59:11.000Z","updated_at":"2023-07-04T12:51:58.000Z","dependencies_parsed_at":"2022-09-26T18:00:39.847Z","dependency_job_id":null,"html_url":"https://github.com/pacedotdev/batch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pacedotdev/batch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacedotdev%2Fbatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacedotdev%2Fbatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacedotdev%2Fbatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacedotdev%2Fbatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pacedotdev","download_url":"https://codeload.github.com/pacedotdev/batch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacedotdev%2Fbatch/sbom","scorecard":{"id":717326,"data":{"date":"2025-08-11","repo":{"name":"github.com/pacedotdev/batch","commit":"d6a9a4d5849f5f13d033b3f51a30d2b4fc0b02a3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"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":"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":"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":"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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/9 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":"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":"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":"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":"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":"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":"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":"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"}}]},"last_synced_at":"2025-08-22T10:06:12.394Z","repository_id":57515760,"created_at":"2025-08-22T10:06:12.394Z","updated_at":"2025-08-22T10:06:12.394Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["golang"],"created_at":"2026-01-12T10:37:04.818Z","updated_at":"2026-01-12T10:37:05.489Z","avatar_url":"https://github.com/pacedotdev.png","language":"Go","readme":"# batch\n\nVery simple batching API for Go.\n\nThis repo came out of a [tutorial blog post](https://pace.dev/blog/2020/02/13/batching-operations-in-go-by-mat-ryer).\n\n## Install\n\nYou might as well just copy the [batch.go](https://github.com/pacedotdev/batch/blob/master/batch.go) file into your own project (and the [batch_test.go](https://github.com/pacedotdev/batch/blob/master/batch_test.go) while you're at it for future generations) rather than adding a dependency.\n\nBut it is maintained as a Go module which you can get with:\n\n```bash\ngo get github.com/pacedotdev/batch\n```\n\n## Usage\n\nImport it:\n\n```go\nimport (\n\t\"github.com/pacedotdev/batch\"\n)\n```\n\nIf we wanted to perform an operation in batches of ten, regardless of how many items were in the slice, we could use the `batch.All` function by passing in the total number of items `len(items)`, and the `batchSize`. The function is a callback that gets called for each batch, with `start` and `end` indexes which you can use to re-slice the `items`:\n\n```go\nitems, err := getAllItemsFromRequest(r)\nif err != nil {\n\treturn errors.Wrap(err, \"getAllItemsFromRequest\")\n}\nbatchSize := 10\nerr := batch.All(len(items), batchSize, func(start, end int) error {\n\tbatchItems := items[start:end]\n\tif err := performSomeRemoteThing(ctx, batchItems); err != nil {\n\t\treturn errors.Wrap(err, \"performSomeRemoteThing\")\n\t}\n})\nif err != nil {\n\treturn err\n}\n```\n\nIn this example, if we got `105` items, the `performSomeRemoteThing` function would get called eleven times, each time with a different page of `10` items (the `batchSize`) except the last time, when it would be a slice of the remaining five items.\n\nThe mechanics are [fairly simple](https://github.com/pacedotdev/batch/blob/master/batch.go), but the code is encapsulated and well tested.\n\n### Using context for cancellation\n\nYou can use a `context.Context` for cancellation by adding a check into the body of the `BatchFunc`. The following code will cancel batching if the user aborts the HTTP request.\n\n```go\nctx := r.Context()\nitems, err := getAllItemsFromRequest(r)\nif err != nil {\n\treturn errors.Wrap(err, \"getAllItemsFromRequest\")\n}\nbatchSize := 10\nerr := batch.All(len(items), batchSize, func(start, end int) error {\n\tif err := ctx.Err(); err != nil {\n\t\treturn err\n\t}\n\tbatchItems := items[start:end]\n\tif err := performSomeRemoteThing(ctx, batchItems); err != nil {\n\t\treturn errors.Wrap(err, \"performSomeRemoteThing\")\n\t}\n})\nif err != nil {\n\treturn err\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacedotdev%2Fbatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacedotdev%2Fbatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacedotdev%2Fbatch/lists"}