Documentation
¶
Overview ¶
Package httputil provides HTTP utility functions for request and response handling.
Index ¶
- Constants
- func HandleBadRequestGin(c *gin.Context, err error, logger *slog.Logger)
- func HandleErrorGin(c *gin.Context, err error, logger *slog.Logger)
- func HandleValidationErrorGin(c *gin.Context, err error, logger *slog.Logger)
- func ParseStringCursorPagination(c *gin.Context, cursorParam string) (afterCursor *string, limit int, err error)
- func ParseUUIDCursorPagination(c *gin.Context, cursorParam string) (afterCursor *uuid.UUID, limit int, err error)
- type ErrorResponse
Constants ¶
const ( // MaxPageLimit is the maximum number of items that can be requested in a single page. // Values exceeding this limit will be clamped to this maximum. MaxPageLimit = 1000 // DefaultPageLimit is the default number of items returned per page if not specified. DefaultPageLimit = 50 )
Variables ¶
This section is empty.
Functions ¶
func HandleBadRequestGin ¶ added in v0.20.0
HandleBadRequestGin writes a 400 Bad Request response for malformed JSON or parameters using Gin.
func HandleErrorGin ¶
HandleErrorGin maps domain errors to HTTP status codes and returns a JSON response using Gin.
func HandleValidationErrorGin ¶
HandleValidationErrorGin writes a 422 Unprocessable Entity response for validation errors using Gin.
func ParseStringCursorPagination ¶ added in v0.25.0
func ParseStringCursorPagination( c *gin.Context, cursorParam string, ) (afterCursor *string, limit int, err error)
ParseStringCursorPagination parses cursor-based pagination parameters for string-based cursors. It accepts a cursor parameter name (e.g., "after_path", "after_name") and returns the parsed string cursor and limit. The cursor is optional (nil if not provided). The limit defaults to 50 and is clamped to 1000.
func ParseUUIDCursorPagination ¶ added in v0.25.0
func ParseUUIDCursorPagination( c *gin.Context, cursorParam string, ) (afterCursor *uuid.UUID, limit int, err error)
ParseUUIDCursorPagination parses cursor-based pagination parameters for UUID-based cursors. It accepts a cursor parameter name (e.g., "after_id") and returns the parsed UUID cursor and limit. The cursor is optional (nil if not provided). The limit defaults to 50 and is clamped to 1000.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"` // Machine-readable error code
Message string `json:"message,omitempty"` // Human-readable error message
Code string `json:"code,omitempty"` // Additional error details (optional)
}
ErrorResponse represents a structured error response returned by the API.