httputils

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeRequest

func DecodeRequest[T any](w http.ResponseWriter, r *http.Request, log *slog.Logger, op string) (T, bool)

DecodeRequest parses and validates JSON body from the request into the given generic struct. Returns the struct and a boolean indicating success or failure.

func SendDataOK

func SendDataOK(w http.ResponseWriter, r *http.Request, log *slog.Logger, op string, data any)

SendDataOK sends a JSON response with the given data and HTTP 200 status. Automatically logs the operation as successful.

func SendOK

func SendOK(w http.ResponseWriter, r *http.Request, log *slog.Logger, op string)

SendOK sends a standard JSON success response with HTTP 200.

func ValidateRequest

func ValidateRequest[T any](w http.ResponseWriter, r *http.Request, log *slog.Logger, op string, req T) bool

ValidateRequest checks the struct against validation tags. Returns true if valid, otherwise sends error response and returns false.

func WriteHTTPError

func WriteHTTPError(w http.ResponseWriter, log *slog.Logger, op string, err error)

WriteHTTPError writes an HTTP error response to w based on the given error. If the error is an apperr.HTTPError, it will be used directly. Otherwise, it will be logged and an internal server error will be written.

Types

This section is empty.

Jump to

Keyboard shortcuts

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