Documentation
¶
Overview ¶
Package middlewares contains server-owned Echo middleware adapters.
Index ¶
- Constants
- func ApplyMiddlewares(e *echo.Echo, config *MiddlewareConfig) error
- func ErrorHandlerWithRecorder(recorder SystemErrorRecorder) echo.HTTPErrorHandler
- func LoginSession(config LoginSessionConfig) (echo.MiddlewareFunc, error)
- func MatchRouteExemption(c *echo.Context, exemptions []RouteExemption) bool
- func RequestContext() echo.MiddlewareFunc
- type APIKeyConfig
- type APIKeyIdentity
- type APIKeyVerifier
- type InstallationGateConfig
- type InstallationStateReader
- type LoginSessionAuthenticator
- type LoginSessionConfig
- type LoginSessionIdentity
- type MiddlewareConfig
- type RouteExemption
- type SystemErrorInput
- type SystemErrorRecorder
- type Validator
Constants ¶
const APIKeyHeader = "X-API-Token"
APIKeyHeader is the header used for back-office API token authentication.
Variables ¶
This section is empty.
Functions ¶
func ApplyMiddlewares ¶
func ApplyMiddlewares(e *echo.Echo, config *MiddlewareConfig) error
ApplyMiddlewares installs server-owned middleware. A nil config is a programming error, not a request for defaults.
func ErrorHandlerWithRecorder ¶
func ErrorHandlerWithRecorder(recorder SystemErrorRecorder) echo.HTTPErrorHandler
ErrorHandlerWithRecorder renders API errors and records internal failures.
func LoginSession ¶
func LoginSession(config LoginSessionConfig) (echo.MiddlewareFunc, error)
LoginSession creates browser login-session authentication middleware.
func MatchRouteExemption ¶
func MatchRouteExemption(c *echo.Context, exemptions []RouteExemption) bool
MatchRouteExemption reports whether the request matches one exemption by exact method and registered route pattern. Route policy forbids path-only, prefix, or wildcard exemptions, so matching is always exact. Middleware packages and business-owned skippers share this executor so the policy has one implementation.
func RequestContext ¶
func RequestContext() echo.MiddlewareFunc
RequestContext stores request-scoped metadata in the standard context.
Types ¶
type APIKeyConfig ¶
type APIKeyConfig struct {
Header string
Verifier APIKeyVerifier
}
APIKeyConfig controls API token authentication middleware. A nil config in MiddlewareConfig leaves the middleware uninstalled; a present config must carry a Verifier.
type APIKeyIdentity ¶
APIKeyIdentity is the request identity produced by a verified API token. Fields are int64 database keys.
type APIKeyVerifier ¶
type APIKeyVerifier interface {
VerifyAPIKey(context.Context, string) (APIKeyIdentity, error)
}
APIKeyVerifier validates a raw API token without exposing token storage to the server.
type InstallationGateConfig ¶
type InstallationGateConfig struct {
Reader InstallationStateReader
Exemptions []RouteExemption
}
InstallationGateConfig controls the uninitialized-system route gate. A nil config in MiddlewareConfig leaves the gate uninstalled; a present config must carry a Reader.
type InstallationStateReader ¶
InstallationStateReader reports whether first initialization has completed.
type LoginSessionAuthenticator ¶
type LoginSessionAuthenticator interface {
AuthenticateLoginSession(context.Context, string) (LoginSessionIdentity, error)
}
LoginSessionAuthenticator validates browser login session credentials.
type LoginSessionConfig ¶
type LoginSessionConfig struct {
CookieName string
Exemptions []RouteExemption
Authenticator LoginSessionAuthenticator
}
LoginSessionConfig controls browser login-session authentication. A nil config in MiddlewareConfig leaves the middleware uninstalled; a present config must carry an Authenticator and the login-session cookie name — the name is Login Session domain policy declared by the auth module and injected by the composition root.
type LoginSessionIdentity ¶
LoginSessionIdentity is the request identity produced by a verified browser login session. Fields are int64 database keys.
type MiddlewareConfig ¶
type MiddlewareConfig struct {
EnableRecovery bool
EnableRequestContext bool
EnableLogger bool
EnableTracing bool
TracingServiceName string
EnableGzip bool
EnableCORS bool
CORS middleware.CORSConfig
APIKey *APIKeyConfig
InstallationGate *InstallationGateConfig
LoginSession *LoginSessionConfig
CSRF middleware.CSRFConfig
}
MiddlewareConfig controls server-owned HTTP middleware.
Activation has a single source of truth per middleware: the Enable* bools below carry genuine runtime configuration, while API-key authentication, the installation gate, and login sessions are installed exactly when their config pointer is non-nil — the composition root constructs the pointer only when the dependency is injected. CSRF follows login sessions because a route without a login session has no CSRF obligation.
type RouteExemption ¶
RouteExemption is one exact HTTP method plus registered route pattern that skips a middleware. Route policy forbids path-only, prefix, or wildcard exemptions, so matching is always exact.
type SystemErrorInput ¶
type SystemErrorInput struct {
Code int
Message string
Detail string
Method string
Path string
IP string
UserAgent string
RequestID string
UserID string
}
SystemErrorInput carries one internal API failure to a persistence adapter.
type SystemErrorRecorder ¶
type SystemErrorRecorder interface {
RecordSystemError(context.Context, SystemErrorInput) error
}
SystemErrorRecorder stores internal API failure diagnostics outside the server.