roundrobin

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 3 Imported by: 0

README

round-robin

Run Tests codecov Go Report Card GoDoc Sourcegraph Release

A go implementation of the Round Robin balancing algorithm.

Installation

To install round-robin package, you need to install Go and set your Go workspace first.

  1. You first need Go installed, then you can use the below Go command to install round-robin.
go get -u github.com/stsmdt/round-robin
  1. Import it in your code:
import roundrobin "github.com/stsmdt/round-robin"

Example

package main

import (
	"net/url"

	roundrobin "github.com/stsmdt/round-robin"
)

func main() {
	rr, _ := roundrobin.New(
		[]url.URL{
			{Host: "127.0.0.1"},
			{Host: "127.0.0.2"},
			{Host: "127.0.0.3"},
			{Host: "127.0.0.4"},
			{Host: "127.0.0.5"},
		},
	)

	rr.Next() // {Host: "127.0.0.1"}
	rr.Next() // {Host: "127.0.0.2"}
	rr.Next() // {Host: "127.0.0.3"}
	rr.Next() // {Host: "127.0.0.4"}
	rr.Next() // {Host: "127.0.0.5"}
	rr.Next() // {Host: "127.0.0.1"}
}

License

This project is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoURLsProvided = errors.New("no urls provided")

ErrNoURLsProvided is the error that no URLs were provided

Functions

This section is empty.

Types

type RoundRobin

type RoundRobin interface {
	Next() url.URL
}

RoundRobin is an interface which represents the round-robin balancing.

func New

func New(urls []url.URL) (RoundRobin, error)

New returns a RoundRobin implementation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL