Help us shape the future of Go! Take the 2026 Go Developer Survey

connection

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionManager

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

ConnectionManager manages reliable connections with retry logic

func NewConnectionManager

func NewConnectionManager(monitor *monitoring.PerformanceMonitor) *ConnectionManager

NewConnectionManager creates a new connection manager

func NewConnectionManagerWithPolicy

func NewConnectionManagerWithPolicy(monitor *monitoring.PerformanceMonitor, policy RetryPolicy) *ConnectionManager

NewConnectionManagerWithPolicy creates a connection manager with custom policy

func (*ConnectionManager) ConnectWithRetry

func (cm *ConnectionManager) ConnectWithRetry(ctx context.Context, target string, port int) (*ConnectionResult, error)

ConnectWithRetry attempts to connect with exponential backoff retry

func (*ConnectionManager) GetConnectionStats

func (cm *ConnectionManager) GetConnectionStats() ConnectionStats

GetConnectionStats returns connection statistics

func (*ConnectionManager) HealthCheckHTTP

func (cm *ConnectionManager) HealthCheckHTTP(ctx context.Context, target string, port int, path string) (*HealthResult, error)

HealthCheckHTTP performs an HTTP health check

func (*ConnectionManager) HealthCheckSSH

func (cm *ConnectionManager) HealthCheckSSH(ctx context.Context, target string, port int) (*HealthResult, error)

HealthCheckSSH performs an SSH health check

func (*ConnectionManager) TestPortAvailability

func (cm *ConnectionManager) TestPortAvailability(ctx context.Context, target string, port int, timeout time.Duration) error

TestPortAvailability tests if a port is available on the target

func (*ConnectionManager) WaitForPortAvailability

func (cm *ConnectionManager) WaitForPortAvailability(ctx context.Context, target string, port int, maxWait time.Duration) error

WaitForPortAvailability waits for a port to become available

type ConnectionResult

type ConnectionResult struct {
	Address   string        `json:"address"`
	Connected bool          `json:"connected"`
	Latency   time.Duration `json:"latency"`
}

ConnectionResult represents a successful connection result

type ConnectionState

type ConnectionState struct {
	Target      string           `json:"target"`
	Status      ConnectionStatus `json:"status"`
	Attempts    int              `json:"attempts"`
	LastAttempt time.Time        `json:"last_attempt"`
	LastError   string           `json:"last_error,omitempty"`
	NextRetry   time.Time        `json:"next_retry,omitempty"`
}

ConnectionState tracks the state of a connection

type ConnectionStats

type ConnectionStats struct {
	TotalConnections    int                      `json:"total_connections"`
	ConnectionsByStatus map[ConnectionStatus]int `json:"connections_by_status"`
}

ConnectionStats provides connection statistics

type ConnectionStatus

type ConnectionStatus string

ConnectionStatus represents connection status

const (
	ConnectionPending    ConnectionStatus = "pending"
	ConnectionConnecting ConnectionStatus = "connecting"
	ConnectionConnected  ConnectionStatus = "connected"
	ConnectionFailed     ConnectionStatus = "failed"
	ConnectionTimeout    ConnectionStatus = "timeout"
)

type DaemonConnectionManager

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

DaemonConnectionManager manages reliable connections to the Prism daemon

func NewDaemonConnectionManager

func NewDaemonConnectionManager(daemonURL string, monitor *monitoring.PerformanceMonitor) (*DaemonConnectionManager, error)

NewDaemonConnectionManager creates a daemon connection manager

func (*DaemonConnectionManager) GetConnectionManager

func (dcm *DaemonConnectionManager) GetConnectionManager() *ConnectionManager

GetConnectionManager returns the underlying connection manager

func (*DaemonConnectionManager) GetConnectionStats

func (dcm *DaemonConnectionManager) GetConnectionStats() DaemonConnectionStats

GetConnectionStats returns connection statistics

func (*DaemonConnectionManager) IsHealthy

func (dcm *DaemonConnectionManager) IsHealthy() bool

IsHealthy returns current daemon health status

func (*DaemonConnectionManager) MakeRequestWithRetry

func (dcm *DaemonConnectionManager) MakeRequestWithRetry(ctx context.Context, req *http.Request) (*http.Response, error)

MakeRequestWithRetry makes an HTTP request with retry logic

func (*DaemonConnectionManager) Start

func (dcm *DaemonConnectionManager) Start(ctx context.Context)

Start begins daemon connection monitoring

func (*DaemonConnectionManager) VerifyDaemonHealth

func (dcm *DaemonConnectionManager) VerifyDaemonHealth(ctx context.Context) error

VerifyDaemonHealth verifies the daemon is healthy via HTTP

func (*DaemonConnectionManager) WaitForDaemon

func (dcm *DaemonConnectionManager) WaitForDaemon(ctx context.Context, maxWait time.Duration) error

WaitForDaemon waits for the daemon to become available

type DaemonConnectionStats

type DaemonConnectionStats struct {
	DaemonURL        string             `json:"daemon_url"`
	IsHealthy        bool               `json:"is_healthy"`
	LastHealthCheck  time.Time          `json:"last_health_check"`
	ConnectionStats  ConnectionStats    `json:"connection_stats"`
	ReliabilityStats ReliabilitySummary `json:"reliability_stats"`
}

DaemonConnectionStats provides daemon connection statistics

type HTTPReliabilityChecker

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

HTTPReliabilityChecker provides HTTP-specific reliability checking

func NewHTTPReliabilityChecker

func NewHTTPReliabilityChecker(rm *ReliabilityManager) *HTTPReliabilityChecker

NewHTTPReliabilityChecker creates an HTTP reliability checker

func (*HTTPReliabilityChecker) CheckHTTPEndpoint

func (hrc *HTTPReliabilityChecker) CheckHTTPEndpoint(ctx context.Context, url string) (*HealthResult, error)

CheckHTTPEndpoint checks an HTTP endpoint for reliability

type HealthResult

type HealthResult struct {
	Service   string        `json:"service"`
	Status    HealthStatus  `json:"status"`
	Message   string        `json:"message,omitempty"`
	Error     string        `json:"error,omitempty"`
	CheckedAt time.Time     `json:"checked_at"`
	Duration  time.Duration `json:"duration"`
}

HealthResult represents a health check result

type HealthStatus

type HealthStatus string

HealthStatus represents health status

const (
	HealthStatusHealthy   HealthStatus = "healthy"
	HealthStatusDegraded  HealthStatus = "degraded"
	HealthStatusUnhealthy HealthStatus = "unhealthy"
	HealthStatusUnknown   HealthStatus = "unknown"
)

type ReliabilityCheck

type ReliabilityCheck struct {
	Target               string            `json:"target"`
	Port                 int               `json:"port"`
	Service              string            `json:"service"`
	Status               ReliabilityStatus `json:"status"`
	ConsecutiveFailures  int               `json:"consecutive_failures"`
	ConsecutiveSuccesses int               `json:"consecutive_successes"`
	TotalChecks          int               `json:"total_checks"`
	SuccessRate          float64           `json:"success_rate"`
	LastCheck            time.Time         `json:"last_check"`
	LastSuccess          time.Time         `json:"last_success"`
	LastFailure          time.Time         `json:"last_failure"`
	ErrorMessage         string            `json:"error_message,omitempty"`
	RecentResults        []bool            `json:"-"` // Sliding window of recent check results (true=success)
}

ReliabilityCheck tracks reliability for a specific target

type ReliabilityManager

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

ReliabilityManager manages connection reliability and automatic recovery

func NewReliabilityManager

func NewReliabilityManager(connMgr *ConnectionManager, monitor *monitoring.PerformanceMonitor) *ReliabilityManager

NewReliabilityManager creates a new reliability manager

func (*ReliabilityManager) AddCheck

func (rm *ReliabilityManager) AddCheck(target string, port int, service string)

AddCheck adds a reliability check for a target

func (*ReliabilityManager) GetAllChecks

func (rm *ReliabilityManager) GetAllChecks() map[string]*ReliabilityCheck

GetAllChecks returns all reliability checks

func (*ReliabilityManager) GetHealthySummary

func (rm *ReliabilityManager) GetHealthySummary() ReliabilitySummary

GetHealthySummary returns a summary of healthy/unhealthy services

func (*ReliabilityManager) GetReliabilityStatus

func (rm *ReliabilityManager) GetReliabilityStatus(target string, port int) (*ReliabilityCheck, bool)

GetReliabilityStatus gets the status for a specific target

func (*ReliabilityManager) IsHealthy

func (rm *ReliabilityManager) IsHealthy(target string, port int) bool

IsHealthy checks if a target is currently healthy

func (*ReliabilityManager) RemoveCheck

func (rm *ReliabilityManager) RemoveCheck(target string, port int)

RemoveCheck removes a reliability check

func (*ReliabilityManager) Start

func (rm *ReliabilityManager) Start(ctx context.Context)

Start begins reliability monitoring

func (*ReliabilityManager) WaitForHealthy

func (rm *ReliabilityManager) WaitForHealthy(ctx context.Context, target string, port int, maxWait time.Duration) error

WaitForHealthy waits for a target to become healthy

type ReliabilityStatus

type ReliabilityStatus string

ReliabilityStatus represents the reliability status

const (
	ReliabilityStatusHealthy    ReliabilityStatus = "healthy"
	ReliabilityStatusDegraded   ReliabilityStatus = "degraded"
	ReliabilityStatusUnhealthy  ReliabilityStatus = "unhealthy"
	ReliabilityStatusRecovering ReliabilityStatus = "recovering"
)

type ReliabilitySummary

type ReliabilitySummary struct {
	TotalChecks        int                       `json:"total_checks"`
	HealthyChecks      int                       `json:"healthy_checks"`
	OverallHealthiness float64                   `json:"overall_healthiness"`
	StatusCounts       map[ReliabilityStatus]int `json:"status_counts"`
}

ReliabilitySummary provides an overview of reliability status

type RetryPolicy

type RetryPolicy struct {
	MaxRetries int           `json:"max_retries"`
	BaseDelay  time.Duration `json:"base_delay"`
	MaxDelay   time.Duration `json:"max_delay"`
	Multiplier float64       `json:"multiplier"`
	Jitter     bool          `json:"jitter"`
}

RetryPolicy defines retry behavior

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

DefaultRetryPolicy returns a sensible default retry policy

type RetryableHTTPClient

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

RetryableHTTPClient wraps http.Client with retry logic

func NewRetryableHTTPClient

func NewRetryableHTTPClient(connMgr *ConnectionManager, monitor *monitoring.PerformanceMonitor) *RetryableHTTPClient

NewRetryableHTTPClient creates an HTTP client with built-in retry logic

func (*RetryableHTTPClient) Do

func (rhc *RetryableHTTPClient) Do(req *http.Request) (*http.Response, error)

Do executes an HTTP request with retry logic

Jump to

Keyboard shortcuts

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