httputil

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 4 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 HandleError added in v1.3.0

func HandleError(w http.ResponseWriter, err error, logger *slog.Logger)

HandleError maps domain errors to HTTP status codes and writes an appropriate response. It logs the error with structured logging and returns a user-friendly error message.

func HandleValidationError added in v1.3.0

func HandleValidationError(w http.ResponseWriter, err error, logger *slog.Logger)

HandleValidationError writes a 400 Bad Request response for validation errors

func MakeJSONResponse

func MakeJSONResponse(w http.ResponseWriter, statusCode int, data interface{})

MakeJSONResponse writes a JSON response with the given status code and data

Types

type ErrorResponse added in v1.3.0

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