Documentation
¶
Index ¶
- Variables
- type BackendStatus
- type Manager
- func (m *Manager) AddBackend(port int, name string, backendURL string) error
- func (m *Manager) BackendStatus(port int, name string) ([]BackendStatus, error)
- func (m *Manager) DeleteBackends(port int, name string) error
- func (m *Manager) GetActive(port int) (string, error)
- func (m *Manager) GetBackends(port int, name string) ([]string, error)
- func (m *Manager) GetSlots(port int) ([]string, error)
- func (m *Manager) RemoveBackend(port int, name string, backendURL string) error
- func (m *Manager) SetBackends(port int, name string, backends []string) error
- func (m *Manager) Start(port int, overrideConfig *ProxyConfig) error
- func (m *Manager) Stop(port int) error
- func (m *Manager) Switch(port int, name string) error
- type ProxyConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProxyExists is returned when trying to start a proxy on a port that is already in use. ErrProxyExists = errors.New("proxy already exists on this port") // ErrProxyNotFound is returned when an operation is attempted on a proxy that does not exist. ErrProxyNotFound = errors.New("proxy not found") // ErrSlotNotFound is returned when an operation is attempted on a slot that does not exist. ErrSlotNotFound = errors.New("slot not found") // ErrInvalidURL is returned when a backend URL is malformed. ErrInvalidURL = errors.New("invalid backend URL") // ErrNoActiveSlot is returned when a request is made to a proxy with no active slot. ErrNoActiveSlot = errors.New("no active slot") )
Functions ¶
This section is empty.
Types ¶
type BackendStatus ¶
type BackendStatus struct {
// URL is the URL of the backend server.
URL string
// Healthy is true if the backend is currently passing health checks.
Healthy bool
}
BackendStatus represents the health and URL of a single backend. This struct is returned by the Manager's BackendStatus method.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the central component for managing reverse proxies. It holds the configuration and state for all running proxies. A Manager should be created using the New function.
func New ¶
func New(logger *slog.Logger, defaultConfig *ProxyConfig) *Manager
New creates a new Manager instance. It takes a logger for structured logging and a defaultConfig that will be applied to all proxies started by this manager. If logger is nil, logs will be discarded. The defaultConfig can be overridden on a per-proxy basis in the Start method.
func (*Manager) AddBackend ¶
AddBackend adds a single backend URL to a named slot. If the slot does not exist, it will be created. This operation is thread-safe.
func (*Manager) BackendStatus ¶
func (m *Manager) BackendStatus(port int, name string) ([]BackendStatus, error)
BackendStatus returns the health status of all backends in a given slot.
func (*Manager) DeleteBackends ¶
DeleteBackends removes a named slot and all its backends from the proxy. If the slot was active, the proxy will have no active slot and may return errors to clients until a new slot is activated via Switch.
func (*Manager) GetBackends ¶
GetBackends returns the list of backend URLs for a given slot.
func (*Manager) RemoveBackend ¶
RemoveBackend removes a single backend URL from a named slot. This operation is thread-safe.
func (*Manager) SetBackends ¶
SetBackends defines or updates a named slot with a list of backend URLs. This operation is thread-safe. If the slot is currently active, the proxy will immediately begin using the new backends. The health of new backends is assumed to be true until the next health check cycle.
func (*Manager) Start ¶
func (m *Manager) Start(port int, overrideConfig *ProxyConfig) error
Start creates and starts a new reverse proxy on the specified port. It launches the proxy's HTTP server in a background goroutine. An optional overrideConfig can be provided to use settings different from the default config provided in the New() function. If overrideConfig is nil, the defaults are used.
type ProxyConfig ¶
type ProxyConfig struct {
// HealthCheckPath is the HTTP path that will be requested to determine a backend's health.
// If this path is empty, health checks will be disabled.
HealthCheckPath string
// HealthCheckInterval is the time between health checks of a backend.
HealthCheckInterval time.Duration
// UnhealthyThreshold is the number of consecutive failed health checks required to mark a backend as unhealthy.
UnhealthyThreshold int
// HealthyThreshold is the number of consecutive successful health checks required to mark an unhealthy backend as healthy again.
HealthyThreshold int
// ClientReadTimeout is the maximum duration for reading the entire request from a client, including the body.
ClientReadTimeout time.Duration
// ClientWriteTimeout is the maximum duration before timing out writes of the response to the client.
ClientWriteTimeout time.Duration
// ClientIdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled.
ClientIdleTimeout time.Duration
// BackendDialTimeout is the maximum duration for establishing a connection to a backend server.
BackendDialTimeout time.Duration
// BackendTransport allows for custom HTTP transport to backend servers.
// If nil, http.DefaultTransport is used.
BackendTransport http.RoundTripper
}
ProxyConfig holds the configuration for a proxy's behavior. It defines settings for health checks and timeouts.