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.
go get github.com/thegeekyasian/round-robin-go
1.18
Since Generics were introduced in go with version 1.18, the project requires go 1.18 to work.
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
one := "One"
two := "Two"
three := "Three"
rr, _ := roundrobin.New(&one, &two, &three)
rr.Next() // One
rr.Next() // Two
rr.Next() // Three
rr.Next() // One
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
round-robin-go is released under MIT license (2023).