{"id":25182100,"url":"https://github.com/ductnn/lba","last_synced_at":"2025-06-24T18:39:19.722Z","repository":{"id":61627414,"uuid":"545002573","full_name":"ductnn/lba","owner":"ductnn","description":"A go implementation of the balancing algorithm","archived":false,"fork":false,"pushed_at":"2022-10-06T14:09:47.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-06-11T18:30:23.713Z","etag":null,"topics":["algorithms","golang","ip-hash","least-connection","load-balancer","round"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ductnn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-03T16:01:36.000Z","updated_at":"2023-03-03T08:15:09.000Z","dependencies_parsed_at":"2022-10-18T17:45:14.836Z","dependency_job_id":null,"html_url":"https://github.com/ductnn/lba","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ductnn/lba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ductnn%2Flba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ductnn%2Flba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ductnn%2Flba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ductnn%2Flba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ductnn","download_url":"https://codeload.github.com/ductnn/lba/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ductnn%2Flba/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261735170,"owners_count":23201971,"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":["algorithms","golang","ip-hash","least-connection","load-balancer","round"],"created_at":"2025-02-09T17:29:47.598Z","updated_at":"2025-06-24T18:39:19.691Z","avatar_url":"https://github.com/ductnn.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LBA\n\n[![Run Tests](https://github.com/ductnn/lba/actions/workflows/test.yml/badge.svg)](https://github.com/ductnn/lba/actions/workflows/test.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ductnn/lba)](https://goreportcard.com/report/github.com/ductnn/lba)\n\n**lba** (LoadBalancer Algorithm) is a [go](https://go.dev/) implementation of the balancing algorithm.\n- Round Robin\n- IP Hash\n- Least Connections\n- **...updating...**\n\n## Installation\n\nFirst, install [Go](https://go.dev/doc/install), and install **lba** package:\n\n```sh\ngo get -u github.com/ductnn/lba\n```\n\nThen, import package in your code:\n\n```go\nimport \"github.com/ductnn/lba\"\n```\n\n## Example\n\n- **Round Robin**:\n\n```go\npackage main\n\nimport (\n\t\"net/url\"\n\n\troundrobin \"github.com/stsmdt/round-robin\"\n)\n\nfunc main() {\n\trr, _ := roundrobin.New(\n\t\t[]url.URL{\n\t\t\t{Host: \"192.168.1.1\"},\n\t\t\t{Host: \"192.168.1.2\"},\n\t\t\t{Host: \"192.168.1.3\"},\n\t\t\t{Host: \"192.168.1.4\"},\n\t\t\t{Host: \"192.168.1.5\"},\n\t\t},\n\t)\n\n\trr.Next() // {Host: \"192.168.1.1\"}\n\trr.Next() // {Host: \"192.168.1.2\"}\n\trr.Next() // {Host: \"192.168.1.3\"}\n\trr.Next() // {Host: \"192.168.1.4\"}\n\trr.Next() // {Host: \"192.168.1.5\"}\n\trr.Next() // {Host: \"192.168.1.1\"}\n}\n```\n\n- **Least Connections**:\n\n```go\nlc, err := New([]*url.URL{\n    {Host: \"192.168.1.10\"},\n    {Host: \"192.168.1.11\"},\n    {Host: \"192.168.1.12\"},\n})\n\nsrc1, done1 := lc.Next() // {Host: \"192.168.1.10\"}\n\nsrc2, done2 := lc.Next() // {Host: \"192.168.1.11\"}\n\ndone1() // Reduce connection of src1\n\nsrc3, done3 := lc.Next() // {Host: \"192.168.1.10\"}\n```\n\n- **IP Hash**:\n\n```go\nip, _ := iphash.New([]*url.URL{\n    {Host: \"192.168.1.10\"},\n    {Host: \"192.168.1.11\"},\n    {Host: \"192.168.1.12\"},\n})\n\nip.Next(\u0026url.URL{Host: \"192.168.1.10\"})  // {Host: \"192.168.1.10\"}\nip.Next(\u0026url.URL{Host: \"192.168.1.10\"})  // {Host: \"192.168.1.10\"}\nip.Next(\u0026url.URL{Host: \"192.168.1.44\"})  // {Host: \"192.168.1.11\"}\nip.Next(\u0026url.URL{Host: \"192.168.1.44\"})  // {Host: \"192.168.1.11\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fductnn%2Flba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fductnn%2Flba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fductnn%2Flba/lists"}