httputil

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package httputil provides HTTP utility functions for request and response handling.

Index

Constants

View Source
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

func HandleBadRequestGin(c *gin.Context, err error, logger *slog.Logger)

HandleBadRequestGin writes a 400 Bad Request response for malformed JSON or parameters using Gin.

func HandleErrorGin

func HandleErrorGin(c *gin.Context, err error, logger *slog.Logger)

HandleErrorGin maps domain errors to HTTP status codes and returns a JSON response using Gin.

func HandleValidationErrorGin

func HandleValidationErrorGin(c *gin.Context, err error, logger *slog.Logger)

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.

Jump to

Keyboard shortcuts

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