Documentation ¶
Index ¶
- Constants
- Variables
- func GetAttemptsFromContext(r *http.Request) int
- func GetRetriesFromContext(r *http.Request) int
- type DefaultServer
- type RoundRobinServerBucket
- func (sb *RoundRobinServerBucket) AddServer(srv Server) error
- func (sb *RoundRobinServerBucket) Healthcheck()
- func (sb *RoundRobinServerBucket) RemoveStale(timeout time.Duration)
- func (sb *RoundRobinServerBucket) RunServices(staleTimeout int)
- func (sb *RoundRobinServerBucket) Serve(w http.ResponseWriter, r *http.Request) error
- func (sb *RoundRobinServerBucket) Size() int
- type Server
- type ServerBucket
Constants ¶
const ( AttemptsKey = "attempts" RetriesKey = "retries" )
const (
RoundRobin = "round-robin"
)
Available loadbalancing algorithms
Variables ¶
var ( ErrInvalidServer = errors.New("expected Server, got nil") ErrNoServersAvailable = errors.New("no servers available") ErrAllServersUnreachable = errors.New("all servers unreachable") )
var (
ErrInvalidAlgorithm = errors.New("invalid balancing algorithm chosen.")
)
Functions ¶
func GetAttemptsFromContext ¶
GetAttemptsFromContext - extract attempts for request
func GetRetriesFromContext ¶
GetAttemptsFromContext - extract the attempts for request
Types ¶
type DefaultServer ¶
type DefaultServer struct {
// contains filtered or unexported fields
}
DefaultServer - default backend server implementation
func (*DefaultServer) Address ¶
func (ds *DefaultServer) Address() *url.URL
Address - getter for server address
func (*DefaultServer) IsAvailable ¶
func (ds *DefaultServer) IsAvailable() bool
IsAvailable - getter for server's availability
func (*DefaultServer) LastSeen ¶
func (ds *DefaultServer) LastSeen() int64
LastSeen - getter for lastSeen time field
func (*DefaultServer) PingServer ¶
func (ds *DefaultServer) PingServer() bool
func (*DefaultServer) ReverseProxy ¶
func (ds *DefaultServer) ReverseProxy() *httputil.ReverseProxy
ReverseProxy - getter for reversing proxy
func (*DefaultServer) SetAvailable ¶
func (ds *DefaultServer) SetAvailable(status bool)
SetAvailable - setter for server's availability
type RoundRobinServerBucket ¶
type RoundRobinServerBucket struct {
// contains filtered or unexported fields
}
RoundRobinServerBucket - round-robin representatino of servers pool
func (*RoundRobinServerBucket) AddServer ¶
func (sb *RoundRobinServerBucket) AddServer(srv Server) error
AddServer - collect Server instance
func (*RoundRobinServerBucket) Healthcheck ¶
func (sb *RoundRobinServerBucket) Healthcheck()
Healthcheck - passive server's availability checks
func (*RoundRobinServerBucket) RemoveStale ¶
func (sb *RoundRobinServerBucket) RemoveStale(timeout time.Duration)
RemoveStale - remove stale servers from storage
func (*RoundRobinServerBucket) RunServices ¶
func (sb *RoundRobinServerBucket) RunServices(staleTimeout int)
RunServices - execute servers pool services
func (*RoundRobinServerBucket) Serve ¶
func (sb *RoundRobinServerBucket) Serve(w http.ResponseWriter, r *http.Request) error
Serve - serve incoming request with server's proxy
func (*RoundRobinServerBucket) Size ¶
func (sb *RoundRobinServerBucket) Size() int
type Server ¶
type Server interface { Address() *url.URL ReverseProxy() *httputil.ReverseProxy IsAvailable() bool SetAvailable(bool) LastSeen() int64 PingServer() bool }
Server - common backend server interface
type ServerBucket ¶
type ServerBucket interface { AddServer(Server) error Size() int Serve(http.ResponseWriter, *http.Request) error Healthcheck() RemoveStale(time.Duration) RunServices(int) }
ServerBucket - common servers pool interface
func New ¶
func New(algo string) (ServerBucket, error)
New - backends pool factory, can use different balancing algorithms in future