Documentation
¶
Index ¶
- Constants
- type Backend
- type BackendConfig
- type BackendControl
- type Backends
- type BackendsConfig
- type Group
- func (g *Group) ActiveCount() (count int)
- func (g *Group) Backends() []*Backend
- func (g *Group) DecreaseConns(addr string)
- func (g *Group) IncreasConns(addr string)
- func (g *Group) IsActive() bool
- func (g *Group) Reset(addrs []string)
- func (g *Group) Select(srcAddr string, onlyHa bool) (addr string)
- func (g *Group) Select2(srcAddr string, onlyHa bool) (isEmpty bool, addr string)
- func (g *Group) Stop()
- type Hash
- func (h *Hash) ActiveCount() (count int)
- func (h *Hash) Backends() []*Backend
- func (h *Hash) DecreaseConns(addr string)
- func (h *Hash) IncreasConns(addr string)
- func (h *Hash) IsActive() bool
- func (h *Hash) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
- func (h *Hash) Select(srcAddr string) (addr string)
- func (h *Hash) SelectBackend(srcAddr string) (b *Backend)
- func (h *Hash) Stop()
- type LeastConn
- func (lc *LeastConn) ActiveCount() (count int)
- func (lc *LeastConn) Backends() []*Backend
- func (lc *LeastConn) DecreaseConns(addr string)
- func (lc *LeastConn) IncreasConns(addr string)
- func (lc *LeastConn) IsActive() bool
- func (lc *LeastConn) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
- func (lc *LeastConn) Select(srcAddr string) (addr string)
- func (lc *LeastConn) SelectBackend(srcAddr string) (b *Backend)
- func (lc *LeastConn) Stop()
- type LeastTime
- func (lt *LeastTime) ActiveCount() (count int)
- func (lt *LeastTime) Backends() []*Backend
- func (lt *LeastTime) DecreaseConns(addr string)
- func (lt *LeastTime) IncreasConns(addr string)
- func (lt *LeastTime) IsActive() bool
- func (lt *LeastTime) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
- func (lt *LeastTime) Select(srcAddr string) (addr string)
- func (lt *LeastTime) SelectBackend(srcAddr string) (b *Backend)
- func (lt *LeastTime) Stop()
- type RoundRobin
- func (r *RoundRobin) ActiveCount() (count int)
- func (r *RoundRobin) Backends() []*Backend
- func (r *RoundRobin) DecreaseConns(addr string)
- func (r *RoundRobin) IncreasConns(addr string)
- func (r *RoundRobin) IsActive() bool
- func (r *RoundRobin) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
- func (r *RoundRobin) Select(srcAddr string) (addr string)
- func (r *RoundRobin) SelectBackend(srcAddr string) (b *Backend)
- func (r *RoundRobin) Stop()
- type Selector
- func NewHash(backends Backends, log *log.Logger, debug bool) Selector
- func NewLeastConn(backends []*Backend, log *log.Logger, debug bool) Selector
- func NewLeastTime(backends []*Backend, log *log.Logger, debug bool) Selector
- func NewRoundRobin(backends Backends, log *log.Logger, debug bool) Selector
- func NewWeight(backends Backends, log *log.Logger, debug bool) Selector
- type Weight
- func (w *Weight) ActiveCount() (count int)
- func (w *Weight) Backends() []*Backend
- func (w *Weight) DecreaseConns(addr string)
- func (w *Weight) IncreasConns(addr string)
- func (w *Weight) IsActive() bool
- func (w *Weight) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
- func (w *Weight) Select(srcAddr string) (addr string)
- func (w *Weight) SelectBackend(srcAddr string) (b *Backend)
- func (w *Weight) Stop()
Constants ¶
View Source
const ( SELECT_ROUNDROBIN = iota SELECT_LEASTCONN SELECT_HASH SELECT_WEITHT SELECT_LEASTTIME )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
BackendConfig
BackendControl
sync.RWMutex
// contains filtered or unexported fields
}
Backend structure
func NewBackend ¶
func NewBackend(backendConfig BackendConfig, dr *dnsx.DomainResolver, log *log.Logger) (*Backend, error)
func (*Backend) DecreaseConns ¶
func (b *Backend) DecreaseConns()
func (*Backend) IncreasConns ¶
func (b *Backend) IncreasConns()
func (*Backend) StartHeartCheck ¶
func (b *Backend) StartHeartCheck()
func (*Backend) StopHeartCheck ¶
func (b *Backend) StopHeartCheck()
type BackendConfig ¶
type BackendConfig struct {
Address string
ActiveAfter int
InactiveAfter int
Weight int
Timeout time.Duration
RetryTime time.Duration
IsMuxCheck bool
ConnFactory func(address string, timeout time.Duration) (net.Conn, error)
}
BackendConfig it's the configuration loaded
type BackendControl ¶
type BackendControl struct {
Failed bool // The last request failed
Active bool
InactiveTries int
ActiveTries int
Connections int
ConnectUsedMillisecond int
// contains filtered or unexported fields
}
BackendControl keep the control data
type BackendsConfig ¶
type BackendsConfig []*BackendConfig
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func NewGroup ¶
func NewGroup(selectType int, configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger, debug bool) Group
func (*Group) ActiveCount ¶
func (*Group) DecreaseConns ¶
func (*Group) IncreasConns ¶
type Hash ¶
########################Hash##########################
func (*Hash) ActiveCount ¶
func (*Hash) DecreaseConns ¶
func (*Hash) IncreasConns ¶
func (*Hash) Reset ¶
func (h *Hash) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
func (*Hash) SelectBackend ¶
type LeastConn ¶
func (*LeastConn) ActiveCount ¶
func (*LeastConn) DecreaseConns ¶
func (*LeastConn) IncreasConns ¶
func (*LeastConn) Reset ¶
func (lc *LeastConn) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
func (*LeastConn) SelectBackend ¶
type LeastTime ¶
func (*LeastTime) ActiveCount ¶
func (*LeastTime) DecreaseConns ¶
func (*LeastTime) IncreasConns ¶
func (*LeastTime) Reset ¶
func (lt *LeastTime) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
func (*LeastTime) SelectBackend ¶
type RoundRobin ¶
########################RoundRobin##########################
func (*RoundRobin) ActiveCount ¶
func (r *RoundRobin) ActiveCount() (count int)
func (*RoundRobin) Backends ¶
func (r *RoundRobin) Backends() []*Backend
func (*RoundRobin) DecreaseConns ¶
func (r *RoundRobin) DecreaseConns(addr string)
func (*RoundRobin) IncreasConns ¶
func (r *RoundRobin) IncreasConns(addr string)
func (*RoundRobin) IsActive ¶
func (r *RoundRobin) IsActive() bool
func (*RoundRobin) Reset ¶
func (r *RoundRobin) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
func (*RoundRobin) Select ¶
func (r *RoundRobin) Select(srcAddr string) (addr string)
func (*RoundRobin) SelectBackend ¶
func (r *RoundRobin) SelectBackend(srcAddr string) (b *Backend)
func (*RoundRobin) Stop ¶
func (r *RoundRobin) Stop()
type Selector ¶
type Selector interface {
Select(srcAddr string) (addr string)
SelectBackend(srcAddr string) (b *Backend)
IncreasConns(addr string)
DecreaseConns(addr string)
Stop()
Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
IsActive() bool
ActiveCount() (count int)
Backends() (bs []*Backend)
}
type Weight ¶
########################Weight##########################
func (*Weight) ActiveCount ¶
func (*Weight) DecreaseConns ¶
func (*Weight) IncreasConns ¶
func (*Weight) Reset ¶
func (w *Weight) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
func (*Weight) SelectBackend ¶
Click to show internal directories.
Click to hide internal directories.