loadbalance

package
v0.0.0-...-76f49ba Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package loadbalance provides the logic to load balance the incoming connections to the upstream servers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHealthCheckFailedAfterRetry is returned when health check fails after retry limit
	ErrHealthCheckFailedAfterRetry = errors.New("health check failed after retry limit")
	// ErrDialerTimeoutExceeded is returned when dialer timeout is exceeded.
	ErrDialerTimeoutExceeded = errors.New("dialer timeout exceeded")
	// ErrDialerIsNil is returned when dialer is nil.
	ErrDialerIsNil = errors.New("dialer is nil")
)

Functions

func HealthCheck

func HealthCheck(
	ctx context.Context,
	server UpstreamServerInterface,
	dialer NetDialerInterface,
) (bool, error)

HealthCheck performs a health check on an upstream server.

Types

type NetDialerInterface

type NetDialerInterface interface {
	Dial(network, address string) (net.Conn, error)
	DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)
	GetTimeout() time.Duration
	GetRetryLimit() int
}

type UpstreamServerInterface

type UpstreamServerInterface interface {
	// GetAddress returns the address of the server.
	GetAddress() string
	// IsHealthy returns the health status of the server.
	IsHealthy() bool
	// SetHealthy sets the health status of the server.
	SetHealthy(healthy bool)
	// IncrementConnectionCount increments the number of connections to the server by 1.
	IncrementConnectionCount()
	// DecrementConnectionCount decrements the number of connections to the server by 1.
	DecrementConnectionCount()
	// GetConnectionCount returns the number of connections to the server.
	GetConnectionCount() int
}

func GetNextUpstreamServer

func GetNextUpstreamServer(upstreamServers []UpstreamServerInterface) (UpstreamServerInterface, error)

Jump to

Keyboard shortcuts

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