balancer

package
v0.0.0-...-de0cf75 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartHealthCheck

func StartHealthCheck(lb *LoadBalancer)

Types

type IPHash

type IPHash struct{}

func (*IPHash) GetNextServer

func (ih *IPHash) GetNextServer(servers []*Server, req *http.Request) *Server

type LeastConnections

type LeastConnections struct{}

func NewLeastConnections

func NewLeastConnections() *LeastConnections

func (*LeastConnections) GetNextServer

func (lc *LeastConnections) GetNextServer(servers []*Server, req *http.Request) *Server

type LoadBalancer

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

func NewLoadBalancer

func NewLoadBalancer(strategy LoadBalancingStrategy, conf *config.Config) *LoadBalancer

func (*LoadBalancer) AddServer

func (lb *LoadBalancer) AddServer(host string, respTime time.Duration)

func (*LoadBalancer) ForwardRequest

func (lb *LoadBalancer) ForwardRequest(res http.ResponseWriter, req *http.Request)

type LoadBalancingStrategy

type LoadBalancingStrategy interface {
	GetNextServer(servers []*Server, req *http.Request) *Server
}

type RoundRobin

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

func NewRoundRobin

func NewRoundRobin() *RoundRobin

func (*RoundRobin) GetNextServer

func (rr *RoundRobin) GetNextServer(servers []*Server, req *http.Request) *Server

type Server

type Server struct {
	Proxy  *proxy.Proxy
	Health bool

	ResponseTimeThreshold time.Duration
	// contains filtered or unexported fields
}

Server represents a backend server.

func NewServer

func NewServer(host string, respTime time.Duration) (*Server, error)

NewServer creates a new Server instance for the given host.

func (*Server) CheckHealth

func (s *Server) CheckHealth() bool

CheckHealth checks the health of the server.

func (*Server) DecrementConnections

func (s *Server) DecrementConnections()

func (*Server) GetActiveConnections

func (s *Server) GetActiveConnections() int

func (*Server) IncrementConnections

func (s *Server) IncrementConnections()

Jump to

Keyboard shortcuts

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