web

package
v0.0.0-...-7018970 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const UserIDKey = contextKey("userID")
View Source
const XUserId = "X-User-Id"

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

func GetUserID

func GetUserID(w http.ResponseWriter, r *http.Request, logger *slog.Logger) (uuid.UUID, bool)

GetUserID retrieves the user ID from the request context. Returns the user ID and a boolean indicating success.

func MapGrpcToHttpStatus

func MapGrpcToHttpStatus(err error) (statusCode int, message string)

func ParseID

func ParseID(w http.ResponseWriter, r *http.Request, logger *slog.Logger) (uuid.UUID, bool)

ParseID extracts and validates the ID from the request path. Returns the ID and a boolean indicating success.

func ParseValidateGt

func ParseValidateGt(r *http.Request, w http.ResponseWriter, logger *slog.Logger, key string, value int64) (int32, bool)

func ParseValidateGte

func ParseValidateGte(r *http.Request, w http.ResponseWriter, logger *slog.Logger, key string, value int64) (int32, bool)

func Recoverer

func Recoverer(logger *slog.Logger) func(next http.Handler) http.Handler

Recoverer is a middleware that recovers from panics and logs them using the provided logger.

func RespondError

func RespondError(w http.ResponseWriter, logger *slog.Logger, status int, message string)

func RespondJSON

func RespondJSON(w http.ResponseWriter, logger *slog.Logger, status int, payload any)

func StructuredLogger

func StructuredLogger(logger *slog.Logger) func(next http.Handler) http.Handler

StructuredLogger creates a middleware that logs HTTP requests in a structured format.

func TelemetryEnricher

func TelemetryEnricher(next http.Handler) http.Handler

TelemetryEnricher — middleware to enrich OTel spans with additional common tags.

Types

type ParamValidator

type ParamValidator func(valueToTest int64) bool

ParamValidator is a function type that validates a parameter.

Jump to

Keyboard shortcuts

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