go_selector

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoundRobinByWeight = 1
	SelectByIPHash     = 2
	SelectByRand       = 3
	RoundRobin         = 4
	SelectByWeightRand = 5
)
View Source
const Ready = "ok"

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

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

func New

func New() *Content

func (*Content) AddNode

func (this *Content) AddNode(nodeSlice ...NodeBalance)

func (*Content) Clear

func (this *Content) Clear()

func (*Content) NeedReLoad

func (this *Content) NeedReLoad(service NodeBalanceSlice) bool

判断是否需要重新加载,也就是nodes对象是否变了 2种情况 1种数量变了,一种数量没变,里面的节点变了

func (*Content) RoundRobin

func (this *Content) RoundRobin() (NodeBalance, error)

func (*Content) RoundRobinByWeight

func (this *Content) RoundRobinByWeight() (NodeBalance, error)

平滑加权轮询

func (*Content) SelectByIPHash

func (this *Content) SelectByIPHash(ip string) (NodeBalance, error)

func (*Content) SelectByRand

func (this *Content) SelectByRand() (NodeBalance, error)

func (*Content) SelectByWeightRand

func (this *Content) SelectByWeightRand() (NodeBalance, error)

type DefaultBalance

type DefaultBalance struct {
	CWeight int
	Status  string
	Weight  int
	Id      string
}

func (*DefaultBalance) GetCWeight

func (this *DefaultBalance) GetCWeight() int

func (*DefaultBalance) GetId

func (this *DefaultBalance) GetId() string

func (*DefaultBalance) GetStatus

func (this *DefaultBalance) GetStatus() string

func (*DefaultBalance) GetWeight

func (this *DefaultBalance) GetWeight() int

func (*DefaultBalance) SetCWeight

func (this *DefaultBalance) SetCWeight(val int)

func (*DefaultBalance) SetWeight

func (this *DefaultBalance) SetWeight(Weight int)

type NodeBalance

type NodeBalance interface {
	GetNode() interface{}
	GetCWeight() int
	GetWeight() int
	GetStatus() string
	SetCWeight(val int)
	SetWeight(Weight int)
	GetId() string
}

type NodeBalanceSlice

type NodeBalanceSlice []NodeBalance

func (NodeBalanceSlice) Len

func (p NodeBalanceSlice) Len() int

func (NodeBalanceSlice) Less

func (p NodeBalanceSlice) Less(i, j int) bool

func (NodeBalanceSlice) Swap

func (p NodeBalanceSlice) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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