Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoServerFound = fmt.Errorf("no server found") ErrInvalidInput = fmt.Errorf("invalidate input") )
Functions ¶
This section is empty.
Types ¶
type BaseLoadBalancer ¶
type BaseLoadBalancer struct {
// contains filtered or unexported fields
}
BaseLoadBalancer loadbalancer instance
func (*BaseLoadBalancer) AddServer ¶
func (b *BaseLoadBalancer) AddServer(srvs []*StatusServer)
AddServer add servers to the lb
func (*BaseLoadBalancer) Choose ¶
func (b *BaseLoadBalancer) Choose(input interface{}) (interface{}, error)
Choose choose server in current lb
func (*BaseLoadBalancer) GetAllStatusServer ¶
func (b *BaseLoadBalancer) GetAllStatusServer() []*StatusServer
func (*BaseLoadBalancer) GetAvailableServer ¶
func (b *BaseLoadBalancer) GetAvailableServer() []*StatusServer
type BaseRule ¶
type BaseRule struct {
// contains filtered or unexported fields
}
BaseRule base rule for all implements, holds the lb to fetch the latest server lists
func (*BaseRule) SetLoadBalancer ¶
func (b *BaseRule) SetLoadBalancer(balancer LoadBalancer)
SetLoadBalancer set the lb for current rule
type IPHashRule ¶
type IPHashRule struct {
BaseRule
}
IPHashRule iphash rule
func (*IPHashRule) Choose ¶
func (i *IPHashRule) Choose(ip interface{}) (interface{}, error)
Choose return the instance by ip hash the input must be ip
type LoadBalancer ¶
type LoadBalancer interface { // GetAllStatusServer return all status server in the lb GetAllStatusServer() []*StatusServer // GetAvailableServer available servers which is ready for service GetAvailableServer() []*StatusServer // AddServer add servers to LoadBalancer AddServer([]*StatusServer) // Choose peek client with rule inside Choose(input interface{}) (interface{}, error) }
LoadBalancer interface to process all grpc client
func NewLoadBalancer ¶
func NewLoadBalancer(lbType conf.LoadBalancerType, srvs []*StatusServer) (LoadBalancer, error)
NewLoadBalancer create new loadbalancer with lb type and servers
type RandomRule ¶
type RandomRule struct {
BaseRule
}
RandomRule random rule by math.Random
func (*RandomRule) Choose ¶
func (r *RandomRule) Choose(interface{}) (interface{}, error)
Choose return the instance by random the input must be ip
type RoundRobinRule ¶
type RoundRobinRule struct { BaseRule // contains filtered or unexported fields }
RoundRobinRule rule with roundrobin algorithm
func (*RoundRobinRule) Choose ¶
func (r *RoundRobinRule) Choose(interface{}) (interface{}, error)
Choose return the instance by roundrobin the input must be ip
type Rule ¶
type Rule interface { // Choose return the instance by rule Choose(interface{}) (interface{}, error) }
Rule for loadbalancer algorithms
type StatusServer ¶
type StatusServer struct { // ReadyForService indicate the remote is connected // and ready for service for client ReadyForService bool // Host holds the eventmesh server host Host string // RealServer holds the grpc client, producer/consumer/heartbeat RealServer interface{} }
StatusServer server with status check
func NewStatusServer ¶
func NewStatusServer(in interface{}, host string) *StatusServer
NewStatusServer create new status server
func (*StatusServer) String ¶
func (s *StatusServer) String() string
String return the description about the server