strategy

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoBackends = errors.New("no backends available")

Functions

This section is empty.

Types

type LC

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

func NewLeastConnected

func NewLeastConnected(backends []*backend.Backend) *LC

func (*LC) Add

func (m *LC) Add(b *backend.Backend)

func (*LC) Backends

func (rr *LC) Backends() []*backend.Backend

func (*LC) OnClose

func (lc *LC) OnClose(addr string)

func (*LC) OnConnect

func (lc *LC) OnConnect(addr string)

func (*LC) Pick

func (lc *LC) Pick() (*backend.Backend, error)

func (*LC) Remove

func (m *LC) Remove(addr string)

type RR

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

func NewRoundRobin

func NewRoundRobin(backends []*backend.Backend) *RR

func (*RR) Add

func (m *RR) Add(b *backend.Backend)

func (*RR) Backends

func (rr *RR) Backends() []*backend.Backend

func (*RR) OnClose

func (rr *RR) OnClose(addr string)

func (*RR) OnConnect

func (rr *RR) OnConnect(addr string)

func (*RR) Pick

func (rr *RR) Pick() (*backend.Backend, error)

func (*RR) Remove

func (m *RR) Remove(addr string)

type Rand

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

func NewRandom

func NewRandom(backends []*backend.Backend) *Rand

func (*Rand) Add

func (m *Rand) Add(b *backend.Backend)

func (*Rand) Backends

func (rr *Rand) Backends() []*backend.Backend

func (*Rand) OnClose

func (r *Rand) OnClose(addr string)

func (*Rand) OnConnect

func (r *Rand) OnConnect(addr string)

func (*Rand) Pick

func (r *Rand) Pick() (*backend.Backend, error)

func (*Rand) Remove

func (m *Rand) Remove(addr string)

type Strategy

type Strategy interface {
	Pick() (*backend.Backend, error)
	Backends() []*backend.Backend
	OnConnect(addr string)
	OnClose(addr string)
	Add(b *backend.Backend)
	Remove(addr string)
}

func NewStrategy

func NewStrategy(typ Type, backends []*backend.Backend) Strategy

type Type

type Type = int
const (
	RoundRobin Type = iota
	WeightRoundRobin
	LeastConnected
	Random
)

type WeightedRR

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

func NewWeightedRR

func NewWeightedRR(backends []*backend.Backend) *WeightedRR

func (*WeightedRR) Add

func (m *WeightedRR) Add(b *backend.Backend)

func (*WeightedRR) Backends

func (rr *WeightedRR) Backends() []*backend.Backend

func (*WeightedRR) OnClose

func (rr *WeightedRR) OnClose(addr string)

func (*WeightedRR) OnConnect

func (rr *WeightedRR) OnConnect(addr string)

func (*WeightedRR) Pick

func (wrr *WeightedRR) Pick() (*backend.Backend, error)

func (*WeightedRR) Remove

func (m *WeightedRR) Remove(addr string)

Jump to

Keyboard shortcuts

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