Documentation
¶
Index ¶
- func GetIPType(ipStr string) string
- func ParseUserAgentPlatform(ua string) string
- type Connection
- type ConnectionStats
- type ConnectionType
- type GeoLocation
- type Handler
- func (h *Handler) GetConnection(c echo.Context) error
- func (h *Handler) GetConnectionGeo(c echo.Context) error
- func (h *Handler) GetStats(c echo.Context) error
- func (h *Handler) ListActiveConnections(c echo.Context) error
- func (h *Handler) LookupIPGeo(c echo.Context) error
- func (h *Handler) RegisterRoutes(g *echo.Group)
- type Manager
- func (m *Manager) GetConnection(id string) *Connection
- func (m *Manager) GetStats() ConnectionStats
- func (m *Manager) ListConnections(connType ConnectionType) []*Connection
- func (m *Manager) Middleware() echo.MiddlewareFunc
- func (m *Manager) RegisterConnection(connType ConnectionType, clientIP, userAgent, path, method string) *Connection
- func (m *Manager) UnregisterConnection(id string)
- func (m *Manager) UpdateConnection(id string, bytesSent, bytesRecv int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseUserAgentPlatform ¶
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 ¶
NewHandler creates a new connection handler.
func (*Handler) GetConnection ¶
GetConnection handles GET /api/v1/connections/:id
func (*Handler) GetConnectionGeo ¶
GetConnectionGeo handles GET /api/v1/connections/:id/geo Returns geographic location for a specific connection's IP (on-demand lookup).
func (*Handler) ListActiveConnections ¶
ListActiveConnections handles GET /api/v1/connections/active
func (*Handler) LookupIPGeo ¶
LookupIPGeo handles POST /api/v1/connections/geo/lookup Allows manual IP geolocation lookup without requiring a connection.
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers the connection API routes.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages active connections.
func NewManager ¶
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 ¶
UnregisterConnection removes a connection.
func (*Manager) UpdateConnection ¶
UpdateConnection updates connection activity.