Documentation
¶
Index ¶
- func AuthenticationFunc(auth UserAuthenticator, apiKeyAuthenticator APIKeyAuthenticator) func(context.Context, *openapi3filter.AuthenticationInput) error
- func ClientIPFromRealIPMiddleware(trustedProxy netip.Addr, logger *slog.Logger) func(http.Handler) http.Handler
- func ClientIPFromRequestMiddleware() func(http.Handler) http.Handler
- func HeartbeatRateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler
- func LoginRateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler
- func MaxBodySizeMiddleware(maxBytes int64) func(http.Handler) http.Handler
- func NewServer(deviceHandler *DeviceHandler, authHandler *AuthHandler, ...) http.Handler
- func RegistrationRateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler
- func RequestLoggerMiddleware(_ *slog.Logger) func(http.Handler) http.Handler
- func StartAndWait(ctx context.Context, handler http.Handler, cfg ServerConfig, ...) error
- type APIKeyAuthenticator
- type AccessLogHandler
- type AuthHandler
- type CompositeHandler
- type DashboardHandler
- type DeviceHandler
- type HostAccessHandler
- type PolicyHandler
- type QueriesHandler
- type RegistrationHandler
- type RuleHandler
- type ServerConfig
- type UserAuthenticator
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 ¶
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 ¶
LoginRateLimitMiddleware rate limits POST /api/v1/auth/login by client IP.
func MaxBodySizeMiddleware ¶
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, registrationHandler *RegistrationHandler, hostAccessHandler *HostAccessHandler, logger *slog.Logger, trustedProxy netip.Addr, ) http.Handler
func RegistrationRateLimitMiddleware ¶ added in v0.3.0
func RegistrationRateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler
RegistrationRateLimitMiddleware rate limits POST /api/v1/register by client IP.
func RequestLoggerMiddleware ¶
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 CompositeHandler ¶
type CompositeHandler struct {
*DeviceHandler
*AuthHandler
*RuleHandler
*QueriesHandler
*AccessLogHandler
*DashboardHandler
*RegistrationHandler
*HostAccessHandler
*PolicyHandler
}
type DashboardHandler ¶
type DashboardHandler = dashboard.HTTPHandler
type DeviceHandler ¶
type DeviceHandler = device.HTTPHandler
type HostAccessHandler ¶ added in v0.3.0
type HostAccessHandler = hostaccess.HTTPHandler
type PolicyHandler ¶
type PolicyHandler = policy.HTTPHandler
type QueriesHandler ¶
type QueriesHandler = queries.HTTPHandler
type RegistrationHandler ¶ added in v0.3.0
type RegistrationHandler = registration.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