weighted

package
v0.0.0-...-a25f934 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrServersEmpty   = errors.New("server list is empty")
	ErrServerNotFound = errors.New("server not found")
)

Functions

This section is empty.

Types

type RoundRobin

type RoundRobin interface {
	NextServer() *url.URL
	AddServer(*url.URL, int) error
	RemoveServer(*url.URL) error
	Servers() []*url.URL
	RemoveAll()
	// Reset resets all current weights.
	Reset()
}
Example
r, _ := New()
for _, server := range servers {
	_ = r.AddServer(server.url, server.weight)
}

fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
Output:

192.168.1.10
192.168.1.10
192.168.1.11
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.10
192.168.1.11
192.168.1.12

func New

func New() (RoundRobin, error)

Jump to

Keyboard shortcuts

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