Documentation
¶
Index ¶
- Variables
- func DecodeJSON(r io.Reader, target any) error
- func DecodeJSONFromRequest(r *http.Request, target any, opts ...Options) error
- func EncodeJSON(w io.Writer, data any, opts ...Options) error
- func RespondWithError(w http.ResponseWriter, err any, opts ...Options) error
- func RespondWithJSON(w http.ResponseWriter, data any, opts ...Options) error
- func RespondWithSuccess(w http.ResponseWriter, data any, meta any, opts ...Options) error
- func Send(w http.ResponseWriter, data any) error
- func SendError(w http.ResponseWriter, err error) error
- func SendSuccess(w http.ResponseWriter, data any) error
- type ErrorDetail
- type Options
- type Response
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes JSON from an io.Reader into the provided target
func DecodeJSONFromRequest ¶
DecodeJSONFromRequest decodes JSON from an HTTP request body
func EncodeJSON ¶
EncodeJSON encodes data to JSON and writes it to the provided writer
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, err any, opts ...Options) error
RespondWithError writes a JSON error response
func RespondWithJSON ¶
func RespondWithJSON(w http.ResponseWriter, data any, opts ...Options) error
RespondWithJSON writes a JSON response with appropriate headers
func RespondWithSuccess ¶
RespondWithSuccess writes a standardized success response
func Send ¶
func Send(w http.ResponseWriter, data any) error
Send is a shorthand for RespondWithJSON with default options
func SendError ¶
func SendError(w http.ResponseWriter, err error) error
SendError is a shorthand for RespondWithError with default options
func SendSuccess ¶
func SendSuccess(w http.ResponseWriter, data any) error
SendSuccess is a shorthand for RespondWithSuccess with default options
Types ¶
type ErrorDetail ¶
type ErrorDetail struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
ErrorDetail represents a structured error with code and message
Click to show internal directories.
Click to hide internal directories.