httpserver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationFunc

func AuthenticationFunc(auth UserAuthenticator, apiKeyAuthenticator APIKeyAuthenticator) func(context.Context, *openapi3filter.AuthenticationInput) error

AuthenticationFunc is called by the OapiRequestValidator to verify security schemes

func ClientIPFromRealIPMiddleware

func ClientIPFromRealIPMiddleware(trustedProxy netip.Addr, logger *slog.Logger) func(http.Handler) http.Handler

ClientIPFromRealIPMiddleware extracts client IP from X-Real-IP only when the direct peer address is within trustedProxy.

If the peer is not trusted, X-Real-IP is ignored to prevent spoofing and a security warning is logged when that header is present.

func ClientIPFromRequestMiddleware

func ClientIPFromRequestMiddleware() func(http.Handler) http.Handler

ClientIPFromRequestMiddleware is middleware that extracts the client IP from r.RemoteAddr and sets it in the request context. It ignores any X-Forwarded-For headers.

func HeartbeatRateLimitMiddleware

func HeartbeatRateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler

HeartbeatRateLimitMiddleware rate limits POST /api/v1/heartbeat by client IP.

func LoginRateLimitMiddleware

func LoginRateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler

LoginRateLimitMiddleware rate limits POST /api/v1/auth/login by client IP.

func MaxBodySizeMiddleware

func MaxBodySizeMiddleware(maxBytes int64) func(http.Handler) http.Handler

MaxBodySizeMiddleware limits request body size to prevent large payloads from exhausting memory.

func NewServer

func NewServer(deviceHandler *DeviceHandler, authHandler *AuthHandler, ruleHandler *RuleHandler, queriesHandler *QueriesHandler, policyHandler *PolicyHandler, accessLogHandler *AccessLogHandler, dashboardHandler *DashboardHandler, logger *slog.Logger, trustedProxy netip.Addr) http.Handler

func RequestLoggerMiddleware

func RequestLoggerMiddleware(_ *slog.Logger) func(http.Handler) http.Handler

RequestLoggerMiddleware stores the request ID in context so the custom slog.Handler can stamp it on every log record produced during this request. The base logger is no longer stored in context; each handler uses its own struct-level logger.

func StartAndWait

func StartAndWait(ctx context.Context, handler http.Handler, cfg ServerConfig, logger *slog.Logger) error

StartAndWait starts the HTTP server in the background. It blocks until a server error occurs or the provided context is cancelled, at which point it performs a graceful shutdown with the configured timeout.

Types

type APIKeyAuthenticator

type APIKeyAuthenticator = device.APIKeyAuthenticator

type AccessLogHandler

type AccessLogHandler = accesslog.HTTPHandler

type AuthHandler

type AuthHandler = auth.HTTPHandler

type DashboardHandler

type DashboardHandler = dashboard.HTTPHandler

type DeviceHandler

type DeviceHandler = device.HTTPHandler

type PolicyHandler

type PolicyHandler = policy.HTTPHandler

type QueriesHandler

type QueriesHandler = queries.HTTPHandler

type RuleHandler

type RuleHandler = rule.HTTPHandler

type ServerConfig

type ServerConfig struct {
	Port              int
	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
	ShutdownTimeout   time.Duration
}

ServerConfig holds configuration for the HTTP server lifecycle.

func DefaultServerConfig

func DefaultServerConfig() ServerConfig

func DefaultServerConfigFromConf

func DefaultServerConfigFromConf(port int) ServerConfig

type UserAuthenticator

type UserAuthenticator = auth.UserAuthenticator

Jump to

Keyboard shortcuts

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