Documentation
¶
Index ¶
- func DecodeRequest[T any](w http.ResponseWriter, r *http.Request, log *slog.Logger, op string) (T, bool)
- func SendDataOK(w http.ResponseWriter, r *http.Request, log *slog.Logger, op string, data any)
- func SendOK(w http.ResponseWriter, r *http.Request, log *slog.Logger, op string)
- func ValidateRequest[T any](w http.ResponseWriter, r *http.Request, log *slog.Logger, op string, req T) bool
- func WriteHTTPError(w http.ResponseWriter, log *slog.Logger, op string, err error)
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 ¶
SendDataOK sends a JSON response with the given data and HTTP 200 status. Automatically logs the operation as successful.
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.