Documentation
¶
Overview ¶
Package server provides HTTP server implementation for the Starmap API.
This file contains general API documentation annotations for Swag/OpenAPI generation. These annotations describe the overall API (title, version, security, etc.) while individual endpoint annotations live in the handler files.
Package server provides HTTP server implementation for the Starmap API.
The server package implements a clean, layered architecture following Go best practices:
- Server: Core server struct with lifecycle management
- Config: Server configuration with sensible defaults
- Router: Route registration and middleware chain
- Handlers: HTTP request handlers organized by domain
The architecture follows the pattern: CLI → App → Server → Router → Handlers
Usage:
cfg := server.DefaultConfig()
cfg.Port = 8080
srv, err := server.New(app, cfg)
if err != nil {
log.Fatal(err)
}
srv.Start() // Start background services
http.ListenAndServe(":8080", srv.Handler())
Package server provides HTTP server implementation for the Starmap API.
Index ¶
- type Config
- type Server
- func (s *Server) Broker() *events.Broker
- func (s *Server) Cache() *cache.Cache
- func (s *Server) Handler() http.Handler
- func (s *Server) SSEBroadcaster() *sse.Broadcaster
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start()
- func (s *Server) StartTime() time.Time
- func (s *Server) WSHub() *ws.Hub
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Server settings
Host string
Port int
// API settings
PathPrefix string
// CORS settings
CORSEnabled bool
CORSOrigins []string
// Authentication settings
AuthEnabled bool
AuthHeader string
// Performance settings
RateLimit int // Requests per minute per IP (0 to disable)
CacheTTL time.Duration
// HTTP timeouts
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
// Shutdown settings
ShutdownGracePeriod time.Duration // Time to wait for background services to shutdown gracefully
// Features
MetricsEnabled bool
}
Config holds server configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the HTTP server state and dependencies.
func New ¶
func New(app application.Application, cfg Config) (*Server, error)
New creates a new server instance with the given configuration.
func (*Server) SSEBroadcaster ¶
func (s *Server) SSEBroadcaster() *sse.Broadcaster
SSEBroadcaster returns the SSE broadcaster.
func (*Server) Shutdown ¶
Shutdown gracefully shuts down background services. The context controls the shutdown timeout - shutdown will abort if context is cancelled.
func (*Server) Start ¶
func (s *Server) Start()
Start starts background services (broker, WebSocket hub, SSE broadcaster).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cache provides an in-memory caching layer for the HTTP server.
|
Package cache provides an in-memory caching layer for the HTTP server. |
|
Package events provides a unified event system for real-time catalog updates.
|
Package events provides a unified event system for real-time catalog updates. |
|
adapters
Package adapters provides transport-specific implementations of the Subscriber interface.
|
Package adapters provides transport-specific implementations of the Subscriber interface. |
|
Package filter provides query parameter parsing and filtering for API endpoints.
|
Package filter provides query parameter parsing and filtering for API endpoints. |
|
Package handlers provides HTTP request handlers for the Starmap API.
|
Package handlers provides HTTP request handlers for the Starmap API. |
|
Package middleware provides HTTP middleware for the Starmap API server.
|
Package middleware provides HTTP middleware for the Starmap API server. |
|
Package response provides standardized HTTP response structures and helpers for the Starmap API server.
|
Package response provides standardized HTTP response structures and helpers for the Starmap API server. |
|
Package sse provides Server-Sent Events support for real-time updates.
|
Package sse provides Server-Sent Events support for real-time updates. |
|
Package websocket provides WebSocket support for real-time catalog updates.
|
Package websocket provides WebSocket support for real-time catalog updates. |