Documentation
¶
Index ¶
Constants ¶
View Source
const ( // ConfigKey carries *Config into lb.Run via context. // ctx = context.WithValue(ctx, lb.ConfigKey, &lb.Config{...}) ConfigKey contextKey = "lb-config" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Backend ¶
type Backend struct {
// Addr is the TCP address of this backend. e.g. "localhost:8080".
// Immutable after creation.
Addr string
// contains filtered or unexported fields
}
Backend represents a single upstream server. All fields that are read concurrently use atomics — no mutex on the hot path.
func (*Backend) ActiveConns ¶
ActiveConns returns the current live connection count for this backend.
func (*Backend) Snapshot ¶
func (b *Backend) Snapshot() BackendSnapshot
Snapshot returns a point-in-time copy of this backend's counters for display.
type BackendSnapshot ¶
type BackendSnapshot struct {
Addr string
Healthy bool
ActiveConns int64
TotalConns int64
TotalBytes int64
}
BackendSnapshot is a plain struct copy of Backend counters — safe to print without holding any locks.
type Config ¶
type Config struct {
// Port the LB listens on for incoming client connections.
Port string
// ID shown in logs.
ID string
// HealthInterval is how often the health checker probes each backend.
// Defaults to 3 seconds if zero.
HealthInterval int // seconds
// contains filtered or unexported fields
}
Config holds everything lb.Run needs. Port and ID are immutable. Algorithm can be changed at runtime by the CLI.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) All ¶
All returns a snapshot of every backend regardless of health — used by CLI display.
Click to show internal directories.
Click to hide internal directories.