Giter Club home page Giter Club logo

thegeekyasian / round-robin-go Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 0.0 6 KB

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.

License: MIT License

Go 100.00%
go golang load-balancer round-robin load-balancing round-robin-scheduler round-robin-simulator roundrobin

round-robin-go's Introduction

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

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

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

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

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

License

round-robin-go is released under MIT license (2023).

round-robin-go's People

Contributors

thegeekyasian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

round-robin-go's Issues

How to assign Array

I have array of workers. Now I want to put these worker in round-robin. How may I pass array in New so that when I do Next task should assign the next worker.

Please help.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.