httpresponse

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

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