Documentation
¶
Index ¶
- Constants
- func CSVResponseEncoder[Response CSVResponse](_ context.Context, w http.ResponseWriter, _ *http.Request, response Response) error
- func DummyErrorEncoder() encoder.ErrorEncoder
- func EmptyResponseEncoder[Response any](statusCode int) encoder.ResponseEncoder[Response]
- func ErrorEncoder(ctx context.Context, _ error, w http.ResponseWriter) bool
- func GenericErrorEncoder() encoder.ErrorEncoder
- func GetMediaType(r *http.Request) (string, error)
- 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 HandleIssueIfHTTPStatusKnown(ctx context.Context, err error, w http.ResponseWriter, ...) bool
- func JSONRequestBodyDecoder(r *http.Request, out any) error
- func JSONResponseEncoder[Response any](_ context.Context, w http.ResponseWriter, _ *http.Request, response Response) error
- func JSONResponseEncoderWithStatus[Response any](statusCode int) encoder.ResponseEncoder[Response]
- func PlainTextResponseEncoder[Response string](_ context.Context, w http.ResponseWriter, _ *http.Request, response Response) error
- func RedirectResponseEncoder[Response string](statusCode int) encoder.ResponseEncoder[Response]
- func WithHTTPStatusCodeAttribute(code int) models.ValidationIssueOption
- type CSVResponse
- type ErrorWithHTTPStatusCode
- type ExtendProblemFunc
- type HTTPStatusAttributePriorizationBehavior
- type HandleIssueIfHTTPStatusKnownOptions
- type Union
Constants ¶
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 CSVResponseEncoder ¶
func CSVResponseEncoder[Response CSVResponse](_ context.Context, w http.ResponseWriter, _ *http.Request, response Response) error
CSVResponseEncoder encodes a response as CSV.
func DummyErrorEncoder ¶
func DummyErrorEncoder() encoder.ErrorEncoder
DummyErrorEncoder is a dummy error encoder that always returns a 400 status code with the received error.
func EmptyResponseEncoder ¶
func EmptyResponseEncoder[Response any](statusCode int) encoder.ResponseEncoder[Response]
func ErrorEncoder ¶
ErrorEncoder encodes an error as HTTP 500 Internal Server Error.
func GenericErrorEncoder ¶
func GenericErrorEncoder() encoder.ErrorEncoder
GenericErrorEncoder is an error encoder that encodes the error as a generic error.
func GetMediaType ¶
GetMediaType returns the media type of the request. If the media type is invalid, it defaults to JSON.
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) map[string]interface{}) 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 HandleIssueIfHTTPStatusKnown ¶
func HandleIssueIfHTTPStatusKnown(ctx context.Context, err error, w http.ResponseWriter, options ...HandleIssueIfHTTPStatusKnownOptions) bool
func JSONResponseEncoder ¶
func JSONResponseEncoder[Response any](_ context.Context, w http.ResponseWriter, _ *http.Request, response Response) error
JSONResponseEncoder encodes a response as JSON.
func JSONResponseEncoderWithStatus ¶
func JSONResponseEncoderWithStatus[Response any](statusCode int) encoder.ResponseEncoder[Response]
func PlainTextResponseEncoder ¶
func PlainTextResponseEncoder[Response string](_ context.Context, w http.ResponseWriter, _ *http.Request, response Response) error
PlainTextResponseEncoder encodes a response as PlainText.
func RedirectResponseEncoder ¶
func RedirectResponseEncoder[Response string](statusCode int) encoder.ResponseEncoder[Response]
func WithHTTPStatusCodeAttribute ¶
func WithHTTPStatusCodeAttribute(code int) models.ValidationIssueOption
Types ¶
type CSVResponse ¶
CSVResponse is a response that can be encoded as CSV.
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 ¶
type ExtendProblemFunc func() map[string]interface{}
func ExtendProblem ¶
func ExtendProblem(name, details string) ExtendProblemFunc
type HTTPStatusAttributePriorizationBehavior ¶
type HTTPStatusAttributePriorizationBehavior string
const ( // In case there are multiple status codes, the errors won't be mapped. This is the default and recommended behavior HTTPStatusAttributePriorizationBehaviorSingular HTTPStatusAttributePriorizationBehavior = "singular" )
type HandleIssueIfHTTPStatusKnownOptions ¶
type HandleIssueIfHTTPStatusKnownOptions func(*handleIssueIfHTTPStatusKnownOptions)
func WithHTTPStatusAttributePriorizationBehavior ¶
func WithHTTPStatusAttributePriorizationBehavior(behavior HTTPStatusAttributePriorizationBehavior) HandleIssueIfHTTPStatusKnownOptions