{"id":20802978,"url":"https://github.com/sv-tools/buffers-pool","last_synced_at":"2025-05-07T01:25:14.424Z","repository":{"id":37980711,"uuid":"355625969","full_name":"sv-tools/buffers-pool","owner":"sv-tools","description":"Go Pool of Byte Buffers","archived":false,"fork":false,"pushed_at":"2025-05-05T08:08:45.000Z","size":95,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-06T12:59:54.528Z","etag":null,"topics":["buffer-management"],"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/sv-tools.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-07T17:16:13.000Z","updated_at":"2025-05-01T23:32:46.000Z","dependencies_parsed_at":"2024-01-08T03:39:57.306Z","dependency_job_id":"7a36de6a-297e-4cb9-a318-0535abcf6b3a","html_url":"https://github.com/sv-tools/buffers-pool","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":"sv-tools/go-repo-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sv-tools%2Fbuffers-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sv-tools%2Fbuffers-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sv-tools%2Fbuffers-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sv-tools%2Fbuffers-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sv-tools","download_url":"https://codeload.github.com/sv-tools/buffers-pool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252794709,"owners_count":21805236,"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":["buffer-management"],"created_at":"2024-11-17T18:39:45.607Z","updated_at":"2025-05-07T01:25:14.402Z","avatar_url":"https://github.com/sv-tools.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# buffers-pool\n[![Code Analysis](https://github.com/sv-tools/buffers-pool/actions/workflows/checks.yaml/badge.svg)](https://github.com/sv-tools/buffers-pool/actions/workflows/checks.yaml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/sv-tools/buffers-pool.svg)](https://pkg.go.dev/github.com/sv-tools/buffers-pool)\n[![codecov](https://codecov.io/gh/sv-tools/buffers-pool/branch/main/graph/badge.svg?token=0XVOTDR1CW)](https://codecov.io/gh/sv-tools/buffers-pool)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/sv-tools/buffers-pool?style=flat)](https://github.com/sv-tools/buffers-pool/releases)\n\nThe small library with an implementation of Buffer Pool.\nThe library was created to avoid repeating this code.\n\nHere is a good article how to implement and properly use the Buffer Pools: https://www.captaincodeman.com/2017/06/02/golang-buffer-pool-gotcha\n\nCheck the [tests](pool_test.go) file for some examples.\n\nPS: The package is stable and the new releases are not expected. \n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n\t\"text/template\"\n\n\tbuffferspool \"github.com/sv-tools/buffers-pool\"\n)\n\nfunc render(tmpl string, data interface{}) (string, error) {\n\ttp, err := template.New(\"test\").Parse(tmpl)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tbuf := buffferspool.Get()\n\tdefer buffferspool.Put(buf)\n\n\tif err := tp.Execute(buf, data); err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// the usage of buf.String is safe \n\treturn buf.String(), nil\n}\n\nfunc main() {\n    var tmpl string\n    var data []interface{}\n    // ... load template and data to variables ...\n\n    var wg sync.WaitGroup\n    res := make(chan string, len(data))\n    for _, d := range data {\n        wg.Add(1)\n        go func(data interface{}) {\n            defer wg.Done()\n            val, err := render(tmpl, data)\n            if err != nil {\n                res \u003c- err.Error()\n                return\n            }\n\n            res \u003c- val\n        }(d)\n    }\n\n    wg.Wait()\n    close(res)\n\n    for val := range res {\n    \tfmt.Println(val)\n\n    }\n}\n```\n\n## License\n\nMIT licensed. See the bundled [LICENSE](LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsv-tools%2Fbuffers-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsv-tools%2Fbuffers-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsv-tools%2Fbuffers-pool/lists"}