{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package server\n\n## Types\n\n```go\ntype Config struct {\n\tName        string\n\tHost        string\n\tPort        int\n\tDescription string\n\n\t// Handler is the http.Handler (e.g., a router) to be served.\n\tHandler http.Handler\n\n\t// GZIP compression support\n\tGZIP bool\n\n\t// HTTP2 enables HTTP/2 with the Extended CONNECT protocol (RFC 8441) for WebSocket support.\n\t// Requires TLS; pair with SSLCert/SSLKey, SelfSignedSSL, or AutoTLS.\n\tHTTP2 bool\n\n\t// TLS/HTTPS configuration options (mutually exclusive)\n\t// Option 1: Provide certificate and key files directly\n\tSSLCert string\n\tSSLKey  string\n\n\t// Option 2: Use self-signed certificate (for development/testing)\n\t// Generates a self-signed certificate automatically if no SSLCert/SSLKey provided\n\tSelfSignedSSL bool\n\n\t// Option 3: Use Let's Encrypt / Certbot for automatic TLS\n\t// AutoTLS enables automatic certificate management via Let's Encrypt\n\tAutoTLS bool\n\t// AutoTLSDomains specifies the domains for Let's Encrypt certificates\n\tAutoTLSDomains []string\n\t// AutoTLSCacheDir specifies where to cache certificates (default: \"./certs-cache\")\n\tAutoTLSCacheDir string\n\t// AutoTLSEmail is the email for Let's Encrypt registration (optional but recommended)\n\tAutoTLSEmail string\n\n\t// PanicHandler is called when a request handler panics.\n\t// If nil, the default middleware.PanicRecovery is used (logs, records metric, returns 500).\n\tPanicHandler func(w http.ResponseWriter, r *http.Request, rcv any)\n\n\t// Graceful shutdown configuration\n\t// ShutdownTimeout is the maximum time to wait for graceful shutdown\n\t// Default: 30 seconds\n\tShutdownTimeout time.Duration\n\n\t// DrainTimeout is the time to wait for in-flight requests to complete\n\t// before forcing shutdown. Default: 25 seconds\n\tDrainTimeout time.Duration\n\n\t// ReadTimeout is the maximum duration for reading the entire request\n\t// Default: 15 seconds\n\tReadTimeout time.Duration\n\n\t// WriteTimeout is the maximum duration before timing out writes of the response\n\t// Default: 15 seconds\n\tWriteTimeout time.Duration\n\n\t// IdleTimeout is the maximum amount of time to wait for the next request\n\t// Default: 60 seconds\n\tIdleTimeout time.Duration\n}\n```\nConfig holds the configuration for a single web server instance.\n\n```go\nfunc FromConfigInstanceToServerConfig(sic *config.ServerInstanceConfig, handler http.Handler) Config\n```\nFromConfigInstanceToServerConfig converts a config.ServerInstanceConfig to server.Config The handler must be provided separately as it cannot be serialized\n\n```go\ntype Instance interface {\n\t// Start begins serving requests. This method should be non-blocking and\n\t// run the server in a separate goroutine.\n\tStart() error\n\n\t// Stop gracefully shuts down the server without interrupting any active connections.\n\t// It accepts a context to allow for a timeout.\n\tStop(ctx context.Context) error\n\n\t// Addr returns the network address the server is listening on.\n\tAddr() string\n\n\t// Name returns the server instance name.\n\tName() string\n\n\t// HealthCheckHandler returns a handler that responds to health checks.\n\t// Returns 200 OK when healthy, 503 Service Unavailable when shutting down.\n\tHealthCheckHandler() http.HandlerFunc\n\n\t// ReadinessHandler returns a handler for readiness checks.\n\t// Includes in-flight request count.\n\tReadinessHandler() http.HandlerFunc\n\n\t// InFlightRequests returns the current number of in-flight requests.\n\tInFlightRequests() int64\n\n\t// IsShuttingDown returns true if the server is shutting down.\n\tIsShuttingDown() bool\n\n\t// Wait blocks until shutdown is complete.\n\tWait()\n}\n```\nInstance defines the interface for a single server instance. It abstracts the underlying http.Server, allowing for easier management and testing.\n\n```go\ntype Manager interface {\n\t// Add registers a new server instance based on the provided configuration.\n\t// The server is not started until StartAll or Start is called on the instance.\n\tAdd(cfg Config) (Instance, error)\n\n\t// Get returns a server instance by its name.\n\tGet(name string) (Instance, error)\n\n\t// Remove stops and removes a server instance by its name.\n\tRemove(name string) error\n\n\t// StartAll starts all registered server instances that are not already running.\n\tStartAll() error\n\n\t// StopAll gracefully shuts down all running server instances.\n\t// Executes shutdown callbacks and drains in-flight requests.\n\tStopAll() error\n\n\t// StopAllWithContext gracefully shuts down all running server instances with a context.\n\tStopAllWithContext(ctx context.Context) error\n\n\t// RestartAll gracefully restarts all running server instances.\n\tRestartAll() error\n\n\t// List returns all registered server instances.\n\tList() []Instance\n\n\t// ServeWithGracefulShutdown starts all servers and blocks until a shutdown signal is received.\n\t// It handles SIGINT and SIGTERM signals and performs graceful shutdown with callbacks.\n\tServeWithGracefulShutdown() error\n\n\t// RegisterShutdownCallback registers a callback to be called during shutdown.\n\t// Useful for cleanup tasks like closing database connections, flushing metrics, etc.\n\tRegisterShutdownCallback(cb ShutdownCallback)\n}\n```\nManager defines the interface for a server manager. It is responsible for managing the lifecycle of multiple server instances.\n\n```go\nfunc NewManager() Manager\n```\nNewManager creates a new server manager.\n\n```go\ntype ShutdownCallback func(context.Context) error\n```\nShutdownCallback is a function called during graceful shutdown.\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/server","name":"server","synopsis":"","isRedistributable":true}
