httputil

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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. This is an adapter for Gin's context that maintains the same error handling logic.

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 ParsePagination added in v0.17.0

func ParsePagination(c *gin.Context) (offset, limit int, err error)

ParsePagination safely parses and validates offset and limit query parameters. It uses default values of 0 for offset and 50 for limit. The limit cannot exceed 100.

Types

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error"`
	Message string `json:"message,omitempty"`
	Code    string `json:"code,omitempty"`
}

ErrorResponse represents a structured error response.

Jump to

Keyboard shortcuts

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