Documentation ¶
Index ¶
- func GetUserID(ctx context.Context) uuid.UUID
- func WithCORS(next http.Handler) http.Handler
- func WithJWTAuth(jwtSecret string, blacklistedPaths []string) func(next http.Handler) http.Handler
- func WithMonitoring(meter otel.Meter) (func(http.Handler) http.Handler, error)
- func WithRecover(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUserID ¶
GetUserID retrieves a user ID from a context, assuming such context comes from an HTTP request with JWT authentication.
func WithCORS ¶
WithCORS sets the necessary headers to enable CORS. TODO: maybe restrict the allowed origins to a specific list.
func WithJWTAuth ¶
WithJWTAuth validates JWT tokens from HTTP requests and adds the user ID to the request's context. If the token is invalid or missing, and the path is not blacklisted, then it returns a 401 Unauthorized response.
func WithMonitoring ¶
WithMonitoring instruments HTTP handlers with OpenTelemetry logs, metrics and traces.
The following metrics are emitted:
- http_requests_total: A counter that tracks the total number of HTTP requests.
- http_request_duration_ms: A histogram that tracks the duration of HTTP requests in milliseconds.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.