balancer

package
v0.0.0-...-be629c2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoHostError                = errors.New("no host")
	AlgorithmNotSupportedError = errors.New("algorithm not supported")
)

Functions

func GetBalancerType

func GetBalancerType() []string

Types

type Algorithm

type Algorithm string

type Balancer

type Balancer interface {
	Add(string)
	Remove(string)
	Balance(string) (string, error)
	Inc(string)
	Done(string)
	Len() int
	Mode() string
}

反向代理的负载均衡器

func Build

func Build(algo Algorithm, hosts []string) (Balancer, error)

func NewConsistenceHash

func NewConsistenceHash(hosts []string) Balancer

func NewRoundRobin

func NewRoundRobin(hosts []string) Balancer

type ConsistenceHash

type ConsistenceHash struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ConsistenceHash) Add

func (c *ConsistenceHash) Add(host string)

func (*ConsistenceHash) Balance

func (c *ConsistenceHash) Balance(url string) (string, error)

func (*ConsistenceHash) Done

func (c *ConsistenceHash) Done(_ string)

Done .

func (*ConsistenceHash) Inc

func (c *ConsistenceHash) Inc(_ string)

Inc .

func (*ConsistenceHash) Len

func (c *ConsistenceHash) Len() int

func (*ConsistenceHash) Mode

func (c *ConsistenceHash) Mode() string

func (*ConsistenceHash) Remove

func (c *ConsistenceHash) Remove(host string)

type Factory

type Factory func([]string) Balancer

type Hash

type Hash func(data []byte) uint32

type RoundRobin

type RoundRobin struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

轮询负载均衡器

func (*RoundRobin) Add

func (r *RoundRobin) Add(host string)

func (*RoundRobin) Balance

func (r *RoundRobin) Balance(_ string) (string, error)

func (*RoundRobin) Done

func (r *RoundRobin) Done(_ string)

Done .

func (*RoundRobin) Inc

func (r *RoundRobin) Inc(_ string)

Inc .

func (*RoundRobin) Len

func (r *RoundRobin) Len() int

func (*RoundRobin) Mode

func (r *RoundRobin) Mode() string

func (*RoundRobin) Remove

func (r *RoundRobin) Remove(host string)

Jump to

Keyboard shortcuts

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