apiutil

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSONBody

func DecodeJSONBody(r *http.Request, dst any, allowEmpty bool) error

DecodeJSONBody decodes a single JSON object from the request body.

func RecordRequestError

func RecordRequestError(w http.ResponseWriter, code string, cause error)

RecordRequestError records the API error on a compatible response writer.

func WriteError

func WriteError(w http.ResponseWriter, _ *http.Request, e *APIError)

WriteError writes a structured API error response.

func WriteInternalError

func WriteInternalError(w http.ResponseWriter, r *http.Request, err error)

WriteInternalError writes a generic internal error response.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, body any)

WriteJSON writes a JSON response body.

Types

type APIError

type APIError struct {
	Status  int
	Code    string
	Message string
	Cause   error
	Fields  []gatewayapi.FieldError
}

APIError describes an HTTP API error response.

func NewError

func NewError(status int, code string, message string, cause error, fields ...gatewayapi.FieldError) *APIError

NewError returns a new APIError.

func (*APIError) Error

func (e *APIError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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