middleware

package
v0.0.0-...-c99e1c3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserID

func GetUserID(ctx context.Context) uuid.UUID

GetUserID retrieves a user ID from a context, assuming such context comes from an HTTP request with JWT authentication.

func WithCORS

func WithCORS(next http.Handler) http.Handler

WithCORS sets the necessary headers to enable CORS. TODO: maybe restrict the allowed origins to a specific list.

func WithJWTAuth

func WithJWTAuth(jwtSecret string, blacklistedPaths []string) func(next http.Handler) http.Handler

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

func WithMonitoring(meter otel.Meter) (func(http.Handler) http.Handler, error)

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.

func WithRecover

func WithRecover(next http.Handler) http.Handler

WithRecover recovers from panics that occur during the execution of the next http.Handler and handles it gracefully by logging the error and responding with a 500 Internal Server Error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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