Documentation
¶
Index ¶
- Constants
- func EmptyResponseEncoder[Response any](statusCode int) httptransport.ResponseEncoder[Response]
- func ErrorEncoder(ctx context.Context, _ error, w http.ResponseWriter) bool
- func GetSortOrder[TInput comparable](asc TInput, inp *TInput) sortx.Order
- func HandleErrorIfTypeMatches[T error](ctx context.Context, statusCode int, err error, w http.ResponseWriter, ...) bool
- func JSONRequestBodyDecoder(r *http.Request, out any) error
- func JSONResponseEncoder[Response any](_ context.Context, w http.ResponseWriter, response Response) error
- func JSONResponseEncoderWithStatus[Response any](statusCode int) httptransport.ResponseEncoder[Response]
- func PlainTextResponseEncoder[Response string](_ context.Context, w http.ResponseWriter, response Response) error
- type ErrorWithHTTPStatusCode
- type ExtendProblemFunc
- type Union
Constants ¶
View Source
const ( // DefaultPageSize is the default page size for pagination. DefaultPageSize = 100 // MaxPageSize is the maximum page size for pagination. MaxPageSize = 1000 // DefaultPage is the default page number for pagination. DefaultPage = 1 )
Variables ¶
This section is empty.
Functions ¶
func EmptyResponseEncoder ¶
func EmptyResponseEncoder[Response any](statusCode int) httptransport.ResponseEncoder[Response]
func ErrorEncoder ¶
ErrorEncoder encodes an error as HTTP 500 Internal Server Error.
func GetSortOrder ¶
func GetSortOrder[TInput comparable](asc TInput, inp *TInput) sortx.Order
func HandleErrorIfTypeMatches ¶
func HandleErrorIfTypeMatches[T error](ctx context.Context, statusCode int, err error, w http.ResponseWriter, extendedProblemFunc ...func(T) (string, string)) bool
HandleErrorIfTypeMatches checks if the error is of the given type and encodes it as an HTTP error. Using the generic feature we can mandate that the error implements the error interface. This is a must, as the errors.As would panic if the error does not implement the error interface.
func JSONResponseEncoder ¶
func JSONResponseEncoder[Response any](_ context.Context, w http.ResponseWriter, response Response) error
JSONResponseEncoder encodes a response as JSON.
func JSONResponseEncoderWithStatus ¶
func JSONResponseEncoderWithStatus[Response any](statusCode int) httptransport.ResponseEncoder[Response]
func PlainTextResponseEncoder ¶
func PlainTextResponseEncoder[Response string](_ context.Context, w http.ResponseWriter, response Response) error
PlainTextResponseEncoder encodes a response as PlainText.
Types ¶
type ErrorWithHTTPStatusCode ¶
type ErrorWithHTTPStatusCode struct { StatusCode int Extensions []ExtendProblemFunc // contains filtered or unexported fields }
func NewHTTPError ¶
func NewHTTPError(statusCode int, err error, extensions ...ExtendProblemFunc) ErrorWithHTTPStatusCode
func (ErrorWithHTTPStatusCode) EncodeError ¶
func (e ErrorWithHTTPStatusCode) EncodeError(ctx context.Context, w http.ResponseWriter) bool
type ExtendProblemFunc ¶
func ExtendProblem ¶
func ExtendProblem(name, details string) ExtendProblemFunc
Click to show internal directories.
Click to hide internal directories.