connection

package
v0.0.0-...-9e5e0b2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIPType

func GetIPType(ipStr string) string

GetIPType returns a human-readable type for the IP address.

func ParseUserAgentPlatform

func ParseUserAgentPlatform(ua string) string

ParseUserAgentPlatform extracts platform info from User-Agent string.

Types

type Connection

type Connection struct {
	ID           string         `json:"id"`
	Type         ConnectionType `json:"type"`
	ClientIP     string         `json:"client_ip"`
	UserAgent    string         `json:"user_agent,omitempty"`
	Path         string         `json:"path"`
	Method       string         `json:"method,omitempty"`
	ConnectedAt  time.Time      `json:"connected_at"`
	LastActivity time.Time      `json:"last_activity"`
	RequestCount int            `json:"request_count"`
	BytesSent    int64          `json:"bytes_sent"`
	BytesRecv    int64          `json:"bytes_recv"`
	Status       string         `json:"status"` // active, idle, closed
	Metadata     map[string]any `json:"metadata,omitempty"`
	GeoLocation  *GeoLocation   `json:"geo_location,omitempty"`
}

Connection represents an active connection.

type ConnectionStats

type ConnectionStats struct {
	TotalConnections   int            `json:"total_connections"`
	ActiveHTTP         int            `json:"active_http"`
	ActiveWebSocket    int            `json:"active_websocket"`
	ActiveSSE          int            `json:"active_sse"`
	TotalRequests      int64          `json:"total_requests"`
	TotalBytesSent     int64          `json:"total_bytes_sent"`
	TotalBytesRecv     int64          `json:"total_bytes_recv"`
	ConnectionsByIP    map[string]int `json:"connections_by_ip"`
	AvgRequestDuration time.Duration  `json:"avg_request_duration"`
	LastUpdated        time.Time      `json:"last_updated"`
}

ConnectionStats represents connection statistics.

type ConnectionType

type ConnectionType string

ConnectionType represents the type of connection.

const (
	ConnectionTypeHTTP      ConnectionType = "http"
	ConnectionTypeWebSocket ConnectionType = "websocket"
	ConnectionTypeSSE       ConnectionType = "sse"
)

type GeoLocation

type GeoLocation struct {
	Country     string  `json:"country,omitempty"`
	CountryCode string  `json:"country_code,omitempty"`
	Region      string  `json:"region,omitempty"`
	City        string  `json:"city,omitempty"`
	Latitude    float64 `json:"latitude,omitempty"`
	Longitude   float64 `json:"longitude,omitempty"`
	Timezone    string  `json:"timezone,omitempty"`
	ISP         string  `json:"isp,omitempty"`
	IsPrivate   bool    `json:"is_private"`
}

GeoLocation represents geographic location information for an IP.

func GetGeoLocation

func GetGeoLocation(ipStr string) *GeoLocation

GetGeoLocation returns geographic location for an IP address. It first checks if the IP is private/local, then uses cached data or external lookup.

type Handler

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

Handler handles connection-related API endpoints.

func NewHandler

func NewHandler(manager *Manager) *Handler

NewHandler creates a new connection handler.

func (*Handler) GetConnection

func (h *Handler) GetConnection(c echo.Context) error

GetConnection handles GET /api/v1/connections/:id

func (*Handler) GetConnectionGeo

func (h *Handler) GetConnectionGeo(c echo.Context) error

GetConnectionGeo handles GET /api/v1/connections/:id/geo Returns geographic location for a specific connection's IP (on-demand lookup).

func (*Handler) GetStats

func (h *Handler) GetStats(c echo.Context) error

GetStats handles GET /api/v1/connections/stats

func (*Handler) ListActiveConnections

func (h *Handler) ListActiveConnections(c echo.Context) error

ListActiveConnections handles GET /api/v1/connections/active

func (*Handler) LookupIPGeo

func (h *Handler) LookupIPGeo(c echo.Context) error

LookupIPGeo handles POST /api/v1/connections/geo/lookup Allows manual IP geolocation lookup without requiring a connection.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(g *echo.Group)

RegisterRoutes registers the connection API routes.

type Manager

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

Manager manages active connections.

func NewManager

func NewManager(maxConns int, idleTimeout time.Duration) *Manager

NewManager creates a new connection manager.

func (*Manager) GetConnection

func (m *Manager) GetConnection(id string) *Connection

GetConnection retrieves a connection by ID.

func (*Manager) GetStats

func (m *Manager) GetStats() ConnectionStats

GetStats returns connection statistics.

func (*Manager) ListConnections

func (m *Manager) ListConnections(connType ConnectionType) []*Connection

ListConnections returns all active connections.

func (*Manager) Middleware

func (m *Manager) Middleware() echo.MiddlewareFunc

Middleware creates an Echo middleware for tracking connections.

func (*Manager) RegisterConnection

func (m *Manager) RegisterConnection(connType ConnectionType, clientIP, userAgent, path, method string) *Connection

RegisterConnection registers a new connection.

func (*Manager) UnregisterConnection

func (m *Manager) UnregisterConnection(id string)

UnregisterConnection removes a connection.

func (*Manager) UpdateConnection

func (m *Manager) UpdateConnection(id string, bytesSent, bytesRecv int64)

UpdateConnection updates connection activity.

Jump to

Keyboard shortcuts

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