lb

package
v1.59.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 3 Imported by: 0

README

Package lb

Пакет lb предоставляет функциональность балансировки нагрузки.

Types

RoundRobin

Структура RoundRobin реализует алгоритм балансировки нагрузки Round Robin.

Methods:

NewRoundRobin(hosts []string) *RoundRobin

Конструктор, принимающий на вход список адресов для балансировки.

(b *RoundRobin) Upgrade(hosts []string)

Обновить список адресов.

(b *RoundRobin) Size() int

Получить текущее количество адресов.

(b *RoundRobin) Next() (string, error)

Получить следующий адрес по алгоритму Round Robin. Если список адресов пуст, то возвращается ошибка.

Usage

Default usage flow
package main

import (
	"log"

	"github.com/txix-open/isp-kit/lb"
)

func main() {
	hostList := []string{"localhost:8080", "localhost:8081"}
	loadBalancer := lb.NewRoundRobin(hostList)

	/* host – random address from hostList*/
	host, err := loadBalancer.Next()
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHostsToBalance = errors.New("no hosts to balance")
)

Functions

This section is empty.

Types

type RoundRobin

type RoundRobin struct {
	// contains filtered or unexported fields
}

func NewRoundRobin

func NewRoundRobin(hosts []string) *RoundRobin

func (*RoundRobin) Next

func (b *RoundRobin) Next() (string, error)

func (*RoundRobin) Size

func (b *RoundRobin) Size() int

func (*RoundRobin) Upgrade

func (b *RoundRobin) Upgrade(hosts []string)

Jump to

Keyboard shortcuts

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