https://github.com/thegeekyasian/round-robin-go
round-robin-go is an implementation of round-robin algorithm that allows you to use your resources in a shared rational order. This project uses go generics that enables you to use any data type in your round robin implementation.
https://github.com/thegeekyasian/round-robin-go
go golang load-balancer load-balancing round-robin round-robin-scheduler round-robin-simulator roundrobin
Last synced: 3 months ago
JSON representation
round-robin-go is an implementation of round-robin algorithm that allows you to use your resources in a shared rational order. This project uses go generics that enables you to use any data type in your round robin implementation.
- Host: GitHub
- URL: https://github.com/thegeekyasian/round-robin-go
- Owner: thegeekyasian
- License: mit
- Created: 2023-02-07T11:53:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-05T20:03:13.000Z (about 2 years ago)
- Last Synced: 2024-06-05T22:05:35.102Z (about 2 years ago)
- Topics: go, golang, load-balancer, load-balancing, round-robin, round-robin-scheduler, round-robin-simulator, roundrobin
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 7
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# round-robin-go
round-robin-go is a round robin balancing algorithm written in golang.
The project uses go-generics, that allows you to use round-robin for any data type. With help of go generics, it has become easier for you to plugin `roundrobin` to your project.
## Installation
```shell
go get github.com/thegeekyasian/round-robin-go
```
## Version:
> 1.18
Since Generics were introduced in go with version 1.18, the project requires go 1.18 to work.
## Usage
### any type
```go
type resource struct {
id int
name string
}
...
rr, _ := roundrobin.New(
&resource{1, "resource-1"},
&resource{2, "resource-2"},
&resource{3, "resource-3"},
)
rr.Next() // resource-1
rr.Next() // resource-2
rr.Next() // resource-3
rr.Next() // resource-1
```
### string
```go
one := "One"
two := "Two"
three := "Three"
rr, _ := roundrobin.New(&one, &two, &three)
rr.Next() // One
rr.Next() // Two
rr.Next() // Three
rr.Next() // One
```
### URLs
```go
rr, _ := roundrobin.New(
&url.URL{Host: "192.168.0.1"},
&url.URL{Host: "192.168.0.2"},
&url.URL{Host: "192.168.0.3"},
&url.URL{Host: "192.168.0.4"},
)
rr.Next() // 192.168.0.1
rr.Next() // 192.168.0.2
rr.Next() // 192.168.0.3
rr.Next() // 192.168.0.4
rr.Next() // 192.168.0.1
rr.Next() // 192.168.0.2
```
### Author
* The Geeky Asian
* [Github](https://github.com/thegeekyasian/)
* [Website](https://thegeekyasian.com/)
### License
round-robin-go is released under [MIT license](https://github.com/thegeekyasian/round-robin-go/blob/master/LICENSE) (2023).