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
Click to show internal directories.
Click to hide internal directories.