Documentation
¶
Index ¶
- func SendErrorJSONResponse(ctx context.Context, w http.ResponseWriter, err error)
- func SendJSONResponse(ctx context.Context, w http.ResponseWriter, payload any, ...)
- func SendJSONResponseWithStatus(ctx context.Context, w http.ResponseWriter, statusCode int, payload any, ...)
- func SendPlainTextResponse(ctx context.Context, w http.ResponseWriter, message string)
- func SendPlainTextResponseWithStatus(ctx context.Context, w http.ResponseWriter, statusCode int, message string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendErrorJSONResponse ¶
func SendErrorJSONResponse(ctx context.Context, w http.ResponseWriter, err error)
SendErrorJSONResponse converts err to an *HTTPError (if not already one) and writes the JSON error response. Non-HTTPError errors become 500 Internal Server Error.
ExtraInfo is included or omitted based on the global httperror.SetWithExtraInfo setting. A shallow copy of the HTTPError is made before serialization to avoid mutating the caller's object.
func SendJSONResponse ¶
func SendJSONResponse(ctx context.Context, w http.ResponseWriter, payload any, logResponseJson ...bool)
SendJSONResponse writes a JSON response with HTTP 200. See SendJSONResponseWithStatus for details on logResponseJson.
func SendJSONResponseWithStatus ¶
func SendJSONResponseWithStatus(ctx context.Context, w http.ResponseWriter, statusCode int, payload any, logResponseJson ...bool)
SendJSONResponseWithStatus marshals payload to JSON and writes it with the given status code. A nil payload is serialized as an empty JSON object {}.
If marshaling fails, a 500 response is sent instead (nothing is partially written because we marshal to a buffer first).
logResponseJson controls whether the serialized JSON is logged. It defaults to true for convenience, but should be set to false for responses containing sensitive data (e.g., tokens, credentials, PII).
func SendPlainTextResponse ¶
func SendPlainTextResponse(ctx context.Context, w http.ResponseWriter, message string)
SendPlainTextResponse writes a plain text response with HTTP 200.
func SendPlainTextResponseWithStatus ¶
func SendPlainTextResponseWithStatus(ctx context.Context, w http.ResponseWriter, statusCode int, message string)
SendPlainTextResponseWithStatus writes a plain text response with the given status code.
Types ¶
This section is empty.