server

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPServerModule

func NewHTTPServerModule(opts ...Option) fx.Option

NewHTTPServerModule provides HTTP server components for dependency injection. By default, configuration is loaded from viper. Use WithServerConfig for static config (useful for tests).

Types

type BulkheadConfig

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

BulkheadConfig holds HTTP bulkhead (concurrency limiting) configuration.

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"`
}

Config holds the HTTP server configuration.

func (*Config) Validate added in v0.4.3

func (c *Config) Validate() error

Validate validates the configuration values. Zero values are acceptable (will use defaults), but negative values are errors.

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 Option added in v0.4.3

type Option func(*serverOptions)

Option is a functional option for configuring the HTTP server module.

func WithServerConfig added in v0.4.3

func WithServerConfig(cfg Config) Option

WithServerConfig provides a static Config (useful for tests).

type RateLimitConfig

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

RateLimitConfig holds rate limiting configuration.

type Server

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

Server defines the HTTP server interface.

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