server

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPServerModule

func NewHTTPServerModule() fx.Option

Types

type BulkheadConfig

type BulkheadConfig struct {
	Enabled       bool          `mapstructure:"enabled"`
	MaxConcurrent int           `mapstructure:"max-concurrent"`
	Timeout       time.Duration `mapstructure:"timeout"`
}

type Config

type Config struct {
	Port int `mapstructure:"port"`

	// Server connection settings
	Connection ConnectionConfig `mapstructure:"connection"`

	// Request Timeout (middleware-based, returns proper HTTP response)
	Timeout TimeoutConfig `mapstructure:"timeout"`

	// Rate Limiting
	RateLimit RateLimitConfig `mapstructure:"rate-limit"`

	// HTTP Bulkhead
	Bulkhead BulkheadConfig `mapstructure:"bulkhead"`
}

type ConnectionConfig

type ConnectionConfig struct {
	ReadHeaderTimeout time.Duration `mapstructure:"read-header-timeout"` // Time to read request headers (Slowloris protection)
	ReadTimeout       time.Duration `mapstructure:"read-timeout"`        // Time to read entire request (headers + body)
	WriteTimeout      time.Duration `mapstructure:"-"`                   // Auto-calculated, not configurable
	IdleTimeout       time.Duration `mapstructure:"idle-timeout"`        // Keep-alive timeout between requests
	MaxHeaderBytes    int           `mapstructure:"max-header-bytes"`    // Max size of request headers
}

ConnectionConfig contains low-level HTTP server connection settings. These are "hard" timeouts that close the connection without HTTP response.

Note: WriteTimeout is intentionally not configurable. It is automatically calculated as RequestTimeout + buffer to ensure the timeout middleware can send a proper HTTP response before the connection is closed.

type RateLimitConfig

type RateLimitConfig struct {
	Enabled           bool `mapstructure:"enabled"`
	RequestsPerSecond int  `mapstructure:"requests-per-second"`
	Burst             int  `mapstructure:"burst"`
}

type Server

type Server interface {
	Serve() error
	ServeWithReadyCallback(onReady func()) error
	Shutdown(ctx context.Context) error
}

type TimeoutConfig

type TimeoutConfig struct {
	RequestTimeout time.Duration `mapstructure:"request-timeout"` // Max time to handle a request (0 = disabled)
}

TimeoutConfig controls the middleware-based request timeout. Unlike connection timeouts, this returns a proper HTTP 503 response. Timeout is enabled when RequestTimeout > 0.

Jump to

Keyboard shortcuts

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