Documentation
¶
Overview ¶
Package httpio handles encoding and decoding for http i/o. This package is used to standardize request and response handling.
Index ¶
- func CauseIsError(err error) bool
- func HasBadGateway(err error) bool
- func HasBadRequest(err error) bool
- func HasClientClosedRequest(err error) bool
- func HasClientMessage(err error) bool
- func HasConflict(err error) bool
- func HasForbidden(err error) bool
- func HasGatewayTimeout(err error) bool
- func HasInternalServerError(err error) bool
- func HasMethodNotAllowed(err error) bool
- func HasNotAcceptable(err error) bool
- func HasNotFound(err error) bool
- func HasNotImplemented(err error) bool
- func HasRequestEntityTooLarge(err error) bool
- func HasRequestTimeout(err error) bool
- func HasServiceUnavailable(err error) bool
- func HasTooManyRequests(err error) bool
- func HasUnauthorized(err error) bool
- func HasUnprocessableEntity(err error) bool
- func HasUnsupportedMediaType(err error) bool
- func Log(handler func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc
- func Message(err error) string
- func Messages(err error) []string
- func NewBadGateway() errors.Chain
- func NewBadGatewayMessage(message string) errors.Chain
- func NewBadGatewayMessageWithError(err error, message string) errors.Chain
- func NewBadGatewayMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewBadGatewayMessagef(format string, a ...any) errors.Chain
- func NewBadGatewayWithError(err error) errors.Chain
- func NewBadRequest() errors.Chain
- func NewBadRequestMessage(message string) errors.Chain
- func NewBadRequestMessageWithError(err error, message string) errors.Chain
- func NewBadRequestMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewBadRequestMessagef(format string, a ...any) errors.Chain
- func NewBadRequestWithError(err error) errors.Chain
- func NewClientClosedRequest() errors.Chain
- func NewClientClosedRequestMessage(message string) errors.Chain
- func NewClientClosedRequestMessageWithError(err error, message string) errors.Chain
- func NewClientClosedRequestMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewClientClosedRequestMessagef(format string, a ...any) errors.Chain
- func NewClientClosedRequestWithError(err error) errors.Chain
- func NewConflict() errors.Chain
- func NewConflictMessage(message string) errors.Chain
- func NewConflictMessageWithError(err error, message string) errors.Chain
- func NewConflictMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewConflictMessagef(format string, a ...any) errors.Chain
- func NewConflictWithError(err error) errors.Chain
- func NewForbidden() errors.Chain
- func NewForbiddenMessage(message string) errors.Chain
- func NewForbiddenMessageWithError(err error, message string) errors.Chain
- func NewForbiddenMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewForbiddenMessagef(format string, a ...any) errors.Chain
- func NewForbiddenWithError(err error) errors.Chain
- func NewGatewayTimeout() errors.Chain
- func NewGatewayTimeoutMessage(message string) errors.Chain
- func NewGatewayTimeoutMessageWithError(err error, message string) errors.Chain
- func NewGatewayTimeoutMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewGatewayTimeoutMessagef(format string, a ...any) errors.Chain
- func NewGatewayTimeoutWithError(err error) errors.Chain
- func NewInternalServerError() errors.Chain
- func NewInternalServerErrorMessage(message string) errors.Chain
- func NewInternalServerErrorMessageWithError(err error, message string) errors.Chain
- func NewInternalServerErrorMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewInternalServerErrorMessagef(format string, a ...any) errors.Chain
- func NewInternalServerErrorWithError(err error) errors.Chain
- func NewMethodNotAllowed() errors.Chain
- func NewMethodNotAllowedMessage(message string) errors.Chain
- func NewMethodNotAllowedMessageWithError(err error, message string) errors.Chain
- func NewMethodNotAllowedMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewMethodNotAllowedMessagef(format string, a ...any) errors.Chain
- func NewMethodNotAllowedWithError(err error) errors.Chain
- func NewNotAcceptable() errors.Chain
- func NewNotAcceptableMessage(message string) errors.Chain
- func NewNotAcceptableMessageWithError(err error, message string) errors.Chain
- func NewNotAcceptableMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewNotAcceptableMessagef(format string, a ...any) errors.Chain
- func NewNotAcceptableWithError(err error) errors.Chain
- func NewNotFound() errors.Chain
- func NewNotFoundMessage(message string) errors.Chain
- func NewNotFoundMessageWithError(err error, message string) errors.Chain
- func NewNotFoundMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewNotFoundMessagef(format string, a ...any) errors.Chain
- func NewNotFoundWithError(err error) errors.Chain
- func NewNotImplemented() errors.Chain
- func NewNotImplementedMessage(message string) errors.Chain
- func NewNotImplementedMessageWithError(err error, message string) errors.Chain
- func NewNotImplementedMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewNotImplementedMessagef(format string, a ...any) errors.Chain
- func NewNotImplementedWithError(err error) errors.Chain
- func NewRequestEntityTooLarge() errors.Chain
- func NewRequestEntityTooLargeMessage(message string) errors.Chain
- func NewRequestEntityTooLargeMessageWithError(err error, message string) errors.Chain
- func NewRequestEntityTooLargeMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewRequestEntityTooLargeMessagef(format string, a ...any) errors.Chain
- func NewRequestEntityTooLargeWithError(err error) errors.Chain
- func NewRequestTimeout() errors.Chain
- func NewRequestTimeoutMessage(message string) errors.Chain
- func NewRequestTimeoutMessageWithError(err error, message string) errors.Chain
- func NewRequestTimeoutMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewRequestTimeoutMessagef(format string, a ...any) errors.Chain
- func NewRequestTimeoutWithError(err error) errors.Chain
- func NewServiceUnavailable() errors.Chain
- func NewServiceUnavailableMessage(message string) errors.Chain
- func NewServiceUnavailableMessageWithError(err error, message string) errors.Chain
- func NewServiceUnavailableMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewServiceUnavailableMessagef(format string, a ...any) errors.Chain
- func NewServiceUnavailableWithError(err error) errors.Chain
- func NewTooManyRequests() errors.Chain
- func NewTooManyRequestsMessage(message string) errors.Chain
- func NewTooManyRequestsMessageWithError(err error, message string) errors.Chain
- func NewTooManyRequestsMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewTooManyRequestsMessagef(format string, a ...any) errors.Chain
- func NewTooManyRequestsWithError(err error) errors.Chain
- func NewUnauthorized() errors.Chain
- func NewUnauthorizedMessage(message string) errors.Chain
- func NewUnauthorizedMessageWithError(err error, message string) errors.Chain
- func NewUnauthorizedMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewUnauthorizedMessagef(format string, a ...any) errors.Chain
- func NewUnauthorizedWithError(err error) errors.Chain
- func NewUnprocessableEntity() errors.Chain
- func NewUnprocessableEntityMessage(message string) errors.Chain
- func NewUnprocessableEntityMessageWithError(err error, message string) errors.Chain
- func NewUnprocessableEntityMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewUnprocessableEntityMessagef(format string, a ...any) errors.Chain
- func NewUnprocessableEntityWithError(err error) errors.Chain
- func NewUnsupportedMediaType() errors.Chain
- func NewUnsupportedMediaTypeMessage(message string) errors.Chain
- func NewUnsupportedMediaTypeMessageWithError(err error, message string) errors.Chain
- func NewUnsupportedMediaTypeMessageWithErrorf(err error, format string, a ...any) errors.Chain
- func NewUnsupportedMediaTypeMessagef(format string, a ...any) errors.Chain
- func NewUnsupportedMediaTypeWithError(err error) errors.Chain
- func Param[T any](r *http.Request, param ParamType) (val T)
- func WithParams(next http.Handler) http.Handler
- type ClientMessage
- type Encoder
- func (e *Encoder) BadGateway(ctx context.Context) error
- func (e *Encoder) BadGatewayMessage(ctx context.Context, message string) error
- func (e *Encoder) BadGatewayMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) BadGatewayMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) BadGatewayMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) BadGatewayWithError(ctx context.Context, err error) error
- func (e *Encoder) BadRequest(ctx context.Context) error
- func (e *Encoder) BadRequestMessage(ctx context.Context, message string) error
- func (e *Encoder) BadRequestMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) BadRequestMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) BadRequestMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) BadRequestWithError(ctx context.Context, err error) error
- func (e *Encoder) ClientClosedRequest(ctx context.Context) error
- func (e *Encoder) ClientClosedRequestMessage(ctx context.Context, message string) error
- func (e *Encoder) ClientClosedRequestMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) ClientClosedRequestMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) ClientClosedRequestMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) ClientClosedRequestWithError(ctx context.Context, err error) error
- func (e *Encoder) ClientMessage(ctx context.Context, err error) error
- func (e *Encoder) Conflict(ctx context.Context) error
- func (e *Encoder) ConflictMessage(ctx context.Context, message string) error
- func (e *Encoder) ConflictMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) ConflictMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) ConflictMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) ConflictWithError(ctx context.Context, err error) error
- func (e *Encoder) Forbidden(ctx context.Context) error
- func (e *Encoder) ForbiddenMessage(ctx context.Context, message string) error
- func (e *Encoder) ForbiddenMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) ForbiddenMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) ForbiddenMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) ForbiddenWithError(ctx context.Context, err error) error
- func (e *Encoder) GatewayTimeout(ctx context.Context) error
- func (e *Encoder) GatewayTimeoutMessage(ctx context.Context, message string) error
- func (e *Encoder) GatewayTimeoutMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) GatewayTimeoutMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) GatewayTimeoutMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) GatewayTimeoutWithError(ctx context.Context, err error) error
- func (e *Encoder) InternalServerError(ctx context.Context) error
- func (e *Encoder) InternalServerErrorMessage(ctx context.Context, message string) error
- func (e *Encoder) InternalServerErrorMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) InternalServerErrorMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) InternalServerErrorMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) InternalServerErrorWithError(ctx context.Context, err error) error
- func (e *Encoder) MethodNotAllowed(ctx context.Context) error
- func (e *Encoder) MethodNotAllowedMessage(ctx context.Context, message string) error
- func (e *Encoder) MethodNotAllowedMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) MethodNotAllowedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) MethodNotAllowedMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) MethodNotAllowedWithError(ctx context.Context, err error) error
- func (e *Encoder) NotAcceptable(ctx context.Context) error
- func (e *Encoder) NotAcceptableMessage(ctx context.Context, message string) error
- func (e *Encoder) NotAcceptableMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) NotAcceptableMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) NotAcceptableMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) NotAcceptableWithError(ctx context.Context, err error) error
- func (e *Encoder) NotFound(ctx context.Context) error
- func (e *Encoder) NotFoundMessage(ctx context.Context, message string) error
- func (e *Encoder) NotFoundMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) NotFoundMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) NotFoundMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) NotFoundWithError(ctx context.Context, err error) error
- func (e *Encoder) NotImplemented(ctx context.Context) error
- func (e *Encoder) NotImplementedMessage(ctx context.Context, message string) error
- func (e *Encoder) NotImplementedMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) NotImplementedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) NotImplementedMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) NotImplementedWithError(ctx context.Context, err error) error
- func (e *Encoder) Ok(body interface{}) error
- func (e *Encoder) RequestEntityTooLarge(ctx context.Context) error
- func (e *Encoder) RequestEntityTooLargeMessage(ctx context.Context, message string) error
- func (e *Encoder) RequestEntityTooLargeMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) RequestEntityTooLargeMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) RequestEntityTooLargeMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) RequestEntityTooLargeWithError(ctx context.Context, err error) error
- func (e *Encoder) RequestTimeout(ctx context.Context) error
- func (e *Encoder) RequestTimeoutMessage(ctx context.Context, message string) error
- func (e *Encoder) RequestTimeoutMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) RequestTimeoutMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) RequestTimeoutMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) RequestTimeoutWithError(ctx context.Context, err error) error
- func (e *Encoder) ServiceUnavailable(ctx context.Context) error
- func (e *Encoder) ServiceUnavailableMessage(ctx context.Context, message string) error
- func (e *Encoder) ServiceUnavailableMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) ServiceUnavailableMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) ServiceUnavailableMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) ServiceUnavailableWithError(ctx context.Context, err error) error
- func (e *Encoder) StatusCodeWithBody(statusCode int, body interface{}) error
- func (e *Encoder) TooManyRequests(ctx context.Context) error
- func (e *Encoder) TooManyRequestsMessage(ctx context.Context, message string) error
- func (e *Encoder) TooManyRequestsMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) TooManyRequestsMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) TooManyRequestsMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) TooManyRequestsWithError(ctx context.Context, err error) error
- func (e *Encoder) Unauthorized(ctx context.Context) error
- func (e *Encoder) UnauthorizedMessage(ctx context.Context, message string) error
- func (e *Encoder) UnauthorizedMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) UnauthorizedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) UnauthorizedMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) UnauthorizedWithError(ctx context.Context, err error) error
- func (e *Encoder) UnprocessableEntity(ctx context.Context) error
- func (e *Encoder) UnprocessableEntityMessage(ctx context.Context, message string) error
- func (e *Encoder) UnprocessableEntityMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) UnprocessableEntityMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) UnprocessableEntityMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) UnprocessableEntityWithError(ctx context.Context, err error) error
- func (e *Encoder) UnsupportedMediaType(ctx context.Context) error
- func (e *Encoder) UnsupportedMediaTypeMessage(ctx context.Context, message string) error
- func (e *Encoder) UnsupportedMediaTypeMessageWithError(ctx context.Context, err error, message string) error
- func (e *Encoder) UnsupportedMediaTypeMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
- func (e *Encoder) UnsupportedMediaTypeMessagef(ctx context.Context, format string, a ...any) error
- func (e *Encoder) UnsupportedMediaTypeWithError(ctx context.Context, err error) error
- type HTTPEncoder
- type MessageResponse
- type ParamType
- type StructDecoder
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CauseIsError ¶
CauseIsError returns true if the Cause of this error is an error vs a ClientMessage with nil error
func HasBadGateway ¶
HasBadGateway checks if the error contains a BadGateway (502) message
func HasBadRequest ¶
HasBadRequest checks if the error contains a BadRequest (400) message
func HasClientClosedRequest ¶
HasClientClosedRequest checks if the error contains a ClientClosedRequest (499) message
func HasClientMessage ¶
HasClientMessage checks if the error contains a client message
func HasConflict ¶
HasConflict checks if the error contains a Conflict (409) message
func HasForbidden ¶
HasForbidden checks if the error contains a Forbidden (403) message
func HasGatewayTimeout ¶
HasGatewayTimeout checks if the error contains a GatewayTimeout (504) message
func HasInternalServerError ¶
HasInternalServerError checks if the error contains a InternalServerError (500) message
func HasMethodNotAllowed ¶
HasMethodNotAllowed checks if the error contains a MethodNotAllowed (405) message
func HasNotAcceptable ¶
HasNotAcceptable checks if the error contains a NotAcceptable (406) message
func HasNotFound ¶
HasNotFound checks if the error contains a NotFound (404) message
func HasNotImplemented ¶
HasNotImplemented checks if the error contains a NotImplemented (501) message
func HasRequestEntityTooLarge ¶
HasRequestEntityTooLarge checks if the error contains a RequestEntityTooLarge (413) message
func HasRequestTimeout ¶
HasRequestTimeout checks if the error contains a RequestTimeout (408) message
func HasServiceUnavailable ¶
HasServiceUnavailable checks if the error contains a ServiceUnavailable (503) message
func HasTooManyRequests ¶
HasTooManyRequests checks if the error contains a TooManyRequests (429) message
func HasUnauthorized ¶
HasUnauthorized checks if the error contains a Unauthorized (401) message
func HasUnprocessableEntity ¶
HasUnprocessableEntity checks if the error contains a UnprocessableEntity (422) message
func HasUnsupportedMediaType ¶
HasUnsupportedMediaType checks if the error contains a UnsupportedMediaType (415) message
func Log ¶
func Log(handler func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc
Log returns a http.HandlerFunc that logs any error coming from handlers. This provides a more ergonomic feel by allowing errors to be returned from handlers
Example usage:
func Handler() http.HandlerFunc {
return httpio.Log(func(w http.ResponseWriter, r *http.Request) error {
// do something
return errors.New("error")
})
}
func Messages ¶
Messages returns a slice of messages from the ClientMessage's contained within the chain of errors
func NewBadGateway ¶
NewBadGateway creates a new empty client message with a BadGateway (502) return code
func NewBadGatewayMessage ¶
NewBadGatewayMessage creates a new client message with a BadGateway (502) return code
func NewBadGatewayMessageWithError ¶
NewBadGatewayMessageWithError wraps an existing error while creating a new client message with a BadGateway (502) return code
func NewBadGatewayMessageWithErrorf ¶
NewBadGatewayMessageWithErrorf wraps an existing error while creating a new client message with a BadGateway (502) return code
func NewBadGatewayMessagef ¶
NewBadGatewayMessagef creates a new client message with a BadGateway (502) return code
func NewBadGatewayWithError ¶
NewBadGatewayWithError wraps an existing error while creating a new empty client message and a BadGateway (502) return code
func NewBadRequest ¶
NewBadRequest creates a new empty client message with a BadRequest (400) return code
func NewBadRequestMessage ¶
NewBadRequestMessage creates a new client message with a BadRequest (400) return code
func NewBadRequestMessageWithError ¶
NewBadRequestMessageWithError wraps an existing error while creating a new client message with a BadRequest (400) return code
func NewBadRequestMessageWithErrorf ¶
NewBadRequestMessageWithErrorf wraps an existing error while creating a new client message with a BadRequest (400) return code
func NewBadRequestMessagef ¶
NewBadRequestMessagef creates a new client message with a BadRequest (400) return code
func NewBadRequestWithError ¶
NewBadRequestWithError wraps an existing error while creating a new empty client message and a BadRequest (400) return code
func NewClientClosedRequest ¶
NewClientClosedRequest creates a new empty client message with a ClientClosedRequest (499) return code
func NewClientClosedRequestMessage ¶
NewClientClosedRequestMessage creates a new client message with a ClientClosedRequest (499) return code
func NewClientClosedRequestMessageWithError ¶
NewClientClosedRequestMessageWithError wraps an existing error while creating a new client message with a ClientClosedRequest (499) return code
func NewClientClosedRequestMessageWithErrorf ¶
NewClientClosedRequestMessageWithErrorf wraps an existing error while creating a new client message with a ClientClosedRequest (499) return code
func NewClientClosedRequestMessagef ¶
NewClientClosedRequestMessagef creates a new client message with a ClientClosedRequest (499) return code
func NewClientClosedRequestWithError ¶
NewClientClosedRequestWithError wraps an existing error while creating a new empty client message and a ClientClosedRequest (499) return code
func NewConflict ¶
NewConflict creates a new empty client message with a Conflict (409) return code
func NewConflictMessage ¶
NewConflictMessage creates a new client message with a Conflict (409) return code
func NewConflictMessageWithError ¶
NewConflictMessageWithError wraps an existing error while creating a new client message with a Conflict (409) return code
func NewConflictMessageWithErrorf ¶
NewConflictMessageWithErrorf wraps an existing error while creating a new client message with a Conflict (409) return code
func NewConflictMessagef ¶
NewConflictMessagef creates a new client message with a Conflict (409) return code
func NewConflictWithError ¶
NewConflictWithError wraps an existing error while creating a new empty client message and a Conflict (409) return code
func NewForbidden ¶
NewForbidden creates a new empty client message with a Forbidden (403) return code
func NewForbiddenMessage ¶
NewForbiddenMessage creates a new client message with a Forbidden (403) return code
func NewForbiddenMessageWithError ¶
NewForbiddenMessageWithError wraps an existing error while creating a new client message with a Forbidden (403) return code
func NewForbiddenMessageWithErrorf ¶
NewForbiddenMessageWithErrorf wraps an existing error while creating a new client message with a Forbidden (403) return code
func NewForbiddenMessagef ¶
NewForbiddenMessagef creates a new client message with a Forbidden (403) return code
func NewForbiddenWithError ¶
NewForbiddenWithError wraps an existing error while creating a new empty client message and a Forbidden (403) return code
func NewGatewayTimeout ¶
NewGatewayTimeout creates a new empty client message with a GatewayTimeout (504) return code
func NewGatewayTimeoutMessage ¶
NewGatewayTimeoutMessage creates a new client message with a GatewayTimeout (504) return code
func NewGatewayTimeoutMessageWithError ¶
NewGatewayTimeoutMessageWithError wraps an existing error while creating a new client message with a GatewayTimeout (504) return code
func NewGatewayTimeoutMessageWithErrorf ¶
NewGatewayTimeoutMessageWithErrorf wraps an existing error while creating a new client message with a GatewayTimeout (504) return code
func NewGatewayTimeoutMessagef ¶
NewGatewayTimeoutMessagef creates a new client message with a GatewayTimeout (504) return code
func NewGatewayTimeoutWithError ¶
NewGatewayTimeoutWithError wraps an existing error while creating a new empty client message and a GatewayTimeout (504) return code
func NewInternalServerError ¶
NewInternalServerError creates a new empty client message with a InternalServerError (500) return code
func NewInternalServerErrorMessage ¶
NewInternalServerErrorMessage creates a new client message with a InternalServerError (500) return code
func NewInternalServerErrorMessageWithError ¶
NewInternalServerErrorMessageWithError wraps an existing error while creating a new client message with a InternalServerError (500) return code
func NewInternalServerErrorMessageWithErrorf ¶
NewInternalServerErrorMessageWithErrorf wraps an existing error while creating a new client message with a InternalServerError (500) return code
func NewInternalServerErrorMessagef ¶
NewInternalServerErrorMessagef creates a new client message with a InternalServerError (500) return code
func NewInternalServerErrorWithError ¶
NewInternalServerErrorWithError wraps an existing error while creating a new empty client message and a InternalServerError (500) return code
func NewMethodNotAllowed ¶
NewMethodNotAllowed creates a new empty client message with a MethodNotAllowed (405) return code
func NewMethodNotAllowedMessage ¶
NewMethodNotAllowedMessage creates a new client message with a MethodNotAllowed (405) return code
func NewMethodNotAllowedMessageWithError ¶
NewMethodNotAllowedMessageWithError wraps an existing error while creating a new client message with a MethodNotAllowed (405) return code
func NewMethodNotAllowedMessageWithErrorf ¶
NewMethodNotAllowedMessageWithErrorf wraps an existing error while creating a new client message with a MethodNotAllowed (405) return code
func NewMethodNotAllowedMessagef ¶
NewMethodNotAllowedMessagef creates a new client message with a MethodNotAllowed (405) return code
func NewMethodNotAllowedWithError ¶
NewMethodNotAllowedWithError wraps an existing error while creating a new empty client message and a MethodNotAllowed (405) return code
func NewNotAcceptable ¶
NewNotAcceptable creates a new empty client message with a NotAcceptable (406) return code
func NewNotAcceptableMessage ¶
NewNotAcceptableMessage creates a new client message with a NotAcceptable (406) return code
func NewNotAcceptableMessageWithError ¶
NewNotAcceptableMessageWithError wraps an existing error while creating a new client message with a NotAcceptable (406) return code
func NewNotAcceptableMessageWithErrorf ¶
NewNotAcceptableMessageWithErrorf wraps an existing error while creating a new client message with a NotAcceptable (406) return code
func NewNotAcceptableMessagef ¶
NewNotAcceptableMessagef creates a new client message with a NotAcceptable (406) return code
func NewNotAcceptableWithError ¶
NewNotAcceptableWithError wraps an existing error while creating a new empty client message and a NotAcceptable (406) return code
func NewNotFound ¶
NewNotFound creates a new empty client message with a NotFound (404) return code
func NewNotFoundMessage ¶
NewNotFoundMessage creates a new client message with a NotFound (404) return code
func NewNotFoundMessageWithError ¶
NewNotFoundMessageWithError wraps an existing error while creating a new client message with a NotFound (404) return code
func NewNotFoundMessageWithErrorf ¶
NewNotFoundMessageWithErrorf wraps an existing error while creating a new client message with a NotFound (404) return code
func NewNotFoundMessagef ¶
NewNotFoundMessagef creates a new client message with a NotFound (404) return code
func NewNotFoundWithError ¶
NewNotFoundWithError wraps an existing error while creating a new empty client message and a NotFound (404) return code
func NewNotImplemented ¶
NewNotImplemented creates a new empty client message with a NotImplemented (501) return code
func NewNotImplementedMessage ¶
NewNotImplementedMessage creates a new client message with a NotImplemented (501) return code
func NewNotImplementedMessageWithError ¶
NewNotImplementedMessageWithError wraps an existing error while creating a new client message with a NotImplemented (501) return code
func NewNotImplementedMessageWithErrorf ¶
NewNotImplementedMessageWithErrorf wraps an existing error while creating a new client message with a NotImplemented (501) return code
func NewNotImplementedMessagef ¶
NewNotImplementedMessagef creates a new client message with a NotImplemented (501) return code
func NewNotImplementedWithError ¶
NewNotImplementedWithError wraps an existing error while creating a new empty client message and a NotImplemented (501) return code
func NewRequestEntityTooLarge ¶
NewRequestEntityTooLarge creates a new empty client message with a RequestEntityTooLarge (413) return code
func NewRequestEntityTooLargeMessage ¶
NewRequestEntityTooLargeMessage creates a new client message with a RequestEntityTooLarge (413) return code
func NewRequestEntityTooLargeMessageWithError ¶
NewRequestEntityTooLargeMessageWithError wraps an existing error while creating a new client message with a RequestEntityTooLarge (413) return code
func NewRequestEntityTooLargeMessageWithErrorf ¶
NewRequestEntityTooLargeMessageWithErrorf wraps an existing error while creating a new client message with a RequestEntityTooLarge (413) return code
func NewRequestEntityTooLargeMessagef ¶
NewRequestEntityTooLargeMessagef creates a new client message with a RequestEntityTooLarge (413) return code
func NewRequestEntityTooLargeWithError ¶
NewRequestEntityTooLargeWithError wraps an existing error while creating a new empty client message and a RequestEntityTooLarge (413) return code
func NewRequestTimeout ¶
NewRequestTimeout creates a new empty client message with a RequestTimeout (408) return code
func NewRequestTimeoutMessage ¶
NewRequestTimeoutMessage creates a new client message with a RequestTimeout (408) return code
func NewRequestTimeoutMessageWithError ¶
NewRequestTimeoutMessageWithError wraps an existing error while creating a new client message with a RequestTimeout (408) return code
func NewRequestTimeoutMessageWithErrorf ¶
NewRequestTimeoutMessageWithErrorf wraps an existing error while creating a new client message with a RequestTimeout (408) return code
func NewRequestTimeoutMessagef ¶
NewRequestTimeoutMessagef creates a new client message with a RequestTimeout (408) return code
func NewRequestTimeoutWithError ¶
NewRequestTimeoutWithError wraps an existing error while creating a new empty client message and a RequestTimeout (408) return code
func NewServiceUnavailable ¶
NewServiceUnavailable creates a new empty client message with a ServiceUnavailable (503) return code
func NewServiceUnavailableMessage ¶
NewServiceUnavailableMessage creates a new client message with a ServiceUnavailable (503) return code
func NewServiceUnavailableMessageWithError ¶
NewServiceUnavailableMessageWithError wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code
func NewServiceUnavailableMessageWithErrorf ¶
NewServiceUnavailableMessageWithErrorf wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code
func NewServiceUnavailableMessagef ¶
NewServiceUnavailableMessagef creates a new client message with a ServiceUnavailable (503) return code
func NewServiceUnavailableWithError ¶
NewServiceUnavailableWithError wraps an existing error while creating a new empty client message and a ServiceUnavailable (503) return code
func NewTooManyRequests ¶
NewTooManyRequests creates a new empty client message with a TooManyRequests (429) return code
func NewTooManyRequestsMessage ¶
NewTooManyRequestsMessage creates a new client message with a TooManyRequests (429) return code
func NewTooManyRequestsMessageWithError ¶
NewTooManyRequestsMessageWithError wraps an existing error while creating a new client message with a TooManyRequests (429) return code
func NewTooManyRequestsMessageWithErrorf ¶
NewTooManyRequestsMessageWithErrorf wraps an existing error while creating a new client message with a TooManyRequests (429) return code
func NewTooManyRequestsMessagef ¶
NewTooManyRequestsMessagef creates a new client message with a TooManyRequests (429) return code
func NewTooManyRequestsWithError ¶
NewTooManyRequestsWithError wraps an existing error while creating a new empty client message and a TooManyRequests (429) return code
func NewUnauthorized ¶
NewUnauthorized creates a new empty client message with a Unauthorized (401) return code
func NewUnauthorizedMessage ¶
NewUnauthorizedMessage creates a new client message with a Unauthorized (401) return code
func NewUnauthorizedMessageWithError ¶
NewUnauthorizedMessageWithError wraps an existing error while creating a new client message with a Unauthorized (401) return code
func NewUnauthorizedMessageWithErrorf ¶
NewUnauthorizedMessageWithErrorf wraps an existing error while creating a new client message with a Unauthorized (401) return code
func NewUnauthorizedMessagef ¶
NewUnauthorizedMessagef creates a new client message with a Unauthorized (401) return code
func NewUnauthorizedWithError ¶
NewUnauthorizedWithError wraps an existing error while creating a new empty client message and a Unauthorized (401) return code
func NewUnprocessableEntity ¶
NewUnprocessableEntity creates a new empty client message with a UnprocessableEntity (422) return code
func NewUnprocessableEntityMessage ¶
NewUnprocessableEntityMessage creates a new client message with a UnprocessableEntity (422) return code
func NewUnprocessableEntityMessageWithError ¶
NewUnprocessableEntityMessageWithError wraps an existing error while creating a new client message with a UnprocessableEntity (422) return code
func NewUnprocessableEntityMessageWithErrorf ¶
NewUnprocessableEntityMessageWithErrorf wraps an existing error while creating a new client message with a UnprocessableEntity (422) return code
func NewUnprocessableEntityMessagef ¶
NewUnprocessableEntityMessagef creates a new client message with a UnprocessableEntity (422) return code
func NewUnprocessableEntityWithError ¶
NewUnprocessableEntityWithError wraps an existing error while creating a new empty client message and a UnprocessableEntity (422) return code
func NewUnsupportedMediaType ¶
NewUnsupportedMediaType creates a new empty client message with a UnsupportedMediaType (415) return code
func NewUnsupportedMediaTypeMessage ¶
NewUnsupportedMediaTypeMessage creates a new client message with a UnsupportedMediaType (415) return code
func NewUnsupportedMediaTypeMessageWithError ¶
NewUnsupportedMediaTypeMessageWithError wraps an existing error while creating a new client message with a UnsupportedMediaType (415) return code
func NewUnsupportedMediaTypeMessageWithErrorf ¶
NewUnsupportedMediaTypeMessageWithErrorf wraps an existing error while creating a new client message with a UnsupportedMediaType (415) return code
func NewUnsupportedMediaTypeMessagef ¶
NewUnsupportedMediaTypeMessagef creates a new client message with a UnsupportedMediaType (415) return code
func NewUnsupportedMediaTypeWithError ¶
NewUnsupportedMediaTypeWithError wraps an existing error while creating a new empty client message and a UnsupportedMediaType (415) return code
func WithParams ¶
WithParams middleware is used to capture Param Parsing errors. They are returned as a http.StatusBadRequest status code with a generic message naming the offending parameter. The underlying parse error is logged server-side and never sent to the client.
Types ¶
type ClientMessage ¶
type ClientMessage struct {
// contains filtered or unexported fields
}
ClientMessage is a custom message type that can be used to return client messages
func (*ClientMessage) Error ¶
func (c *ClientMessage) Error() string
Error returns the error message
func (*ClientMessage) Message ¶
func (c *ClientMessage) Message() string
Message returns the client message
func (*ClientMessage) Unwrap ¶
func (c *ClientMessage) Unwrap() error
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is a struct that is used for encoding http responses
func NewEncoder ¶
func NewEncoder(w http.ResponseWriter) *Encoder
NewEncoder returns a new Encoder to write to the ResponseWriter This encoder will write to the ResponseWriter using a json encoder.
func (*Encoder) BadGateway ¶
BadGateway creates a new empty client message with a BadGateway (502) return code
func (*Encoder) BadGatewayMessage ¶
BadGatewayMessage creates a new client message with a BadGateway (502) return code
func (*Encoder) BadGatewayMessageWithError ¶
BadGatewayMessageWithError wraps an existing error while creating a new client message with a BadGateway (502) return code
func (*Encoder) BadGatewayMessageWithErrorf ¶
func (e *Encoder) BadGatewayMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
BadGatewayMessageWithErrorf wraps an existing error while creating a new client message with a BadGateway (502) return code
func (*Encoder) BadGatewayMessagef ¶
BadGatewayMessagef creates a new client message with a BadGateway (502) return code
func (*Encoder) BadGatewayWithError ¶
BadGatewayWithError wraps an existing error while creating a new empty client message and a BadGateway (502) return code
func (*Encoder) BadRequest ¶
BadRequest creates a new empty client message with a BadRequest (400) return code
func (*Encoder) BadRequestMessage ¶
BadRequestMessage creates a new client message with a BadRequest (400) return code
func (*Encoder) BadRequestMessageWithError ¶
BadRequestMessageWithError wraps an existing error while creating a new client message with a BadRequest (400) return code
func (*Encoder) BadRequestMessageWithErrorf ¶
func (e *Encoder) BadRequestMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
BadRequestMessageWithErrorf wraps an existing error while creating a new client message with a BadRequest (400) return code
func (*Encoder) BadRequestMessagef ¶
BadRequestMessagef creates a new client message with a BadRequest (400) return code
func (*Encoder) BadRequestWithError ¶
BadRequestWithError wraps an existing error while creating a new empty client message and a BadRequest (400) return code
func (*Encoder) ClientClosedRequest ¶
ClientClosedRequest creates a new empty client message with a ClientClosedRequest (499) return code
func (*Encoder) ClientClosedRequestMessage ¶
ClientClosedRequestMessage creates a new client message with a ClientClosedRequest (499) return code
func (*Encoder) ClientClosedRequestMessageWithError ¶
func (e *Encoder) ClientClosedRequestMessageWithError(ctx context.Context, err error, message string) error
ClientClosedRequestMessageWithError wraps an existing error while creating a new client message with a ClientClosedRequest (499) return code
func (*Encoder) ClientClosedRequestMessageWithErrorf ¶
func (e *Encoder) ClientClosedRequestMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
ClientClosedRequestMessageWithErrorf wraps an existing error while creating a new client message with a ClientClosedRequest (499) return code
func (*Encoder) ClientClosedRequestMessagef ¶
ClientClosedRequestMessagef creates a new client message with a ClientClosedRequest (499) return code
func (*Encoder) ClientClosedRequestWithError ¶
ClientClosedRequestWithError wraps an existing error while creating a new empty client message and a ClientClosedRequest (499) return code
func (*Encoder) ClientMessage ¶
ClientMessage sets an http code and formats a client message based upon the message type found in the error chain. If no message type is found it defaults to InternalServerError (500) with no message
func (*Encoder) Conflict ¶
Conflict creates a new empty client message with a Conflict (409) return code
func (*Encoder) ConflictMessage ¶
ConflictMessage creates a new client message with a Conflict (409) return code
func (*Encoder) ConflictMessageWithError ¶
ConflictMessageWithError wraps an existing error while creating a new client message with a Conflict (409) return code
func (*Encoder) ConflictMessageWithErrorf ¶
func (e *Encoder) ConflictMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
ConflictMessageWithErrorf wraps an existing error while creating a new client message with a Conflict (409) return code
func (*Encoder) ConflictMessagef ¶
ConflictMessagef creates a new client message with a Conflict (409) return code
func (*Encoder) ConflictWithError ¶
ConflictWithError wraps an existing error while creating a new empty client message and a Conflict (409) return code
func (*Encoder) Forbidden ¶
Forbidden creates a new empty client message with a Forbidden (403) return code
func (*Encoder) ForbiddenMessage ¶
ForbiddenMessage creates a new client message with a Forbidden (403) return code
func (*Encoder) ForbiddenMessageWithError ¶
ForbiddenMessageWithError wraps an existing error while creating a new client message with a Forbidden (403) return code
func (*Encoder) ForbiddenMessageWithErrorf ¶
func (e *Encoder) ForbiddenMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
ForbiddenMessageWithErrorf wraps an existing error while creating a new client message with a Forbidden (403) return code
func (*Encoder) ForbiddenMessagef ¶
ForbiddenMessagef creates a new client message with a Forbidden (403) return code
func (*Encoder) ForbiddenWithError ¶
ForbiddenWithError wraps an existing error while creating a new empty client message and a Forbidden (403) return code
func (*Encoder) GatewayTimeout ¶
GatewayTimeout creates a new empty client message with a GatewayTimeout (504) return code
func (*Encoder) GatewayTimeoutMessage ¶
GatewayTimeoutMessage creates a new client message with a GatewayTimeout (504) return code
func (*Encoder) GatewayTimeoutMessageWithError ¶
func (e *Encoder) GatewayTimeoutMessageWithError(ctx context.Context, err error, message string) error
GatewayTimeoutMessageWithError wraps an existing error while creating a new client message with a GatewayTimeout (504) return code
func (*Encoder) GatewayTimeoutMessageWithErrorf ¶
func (e *Encoder) GatewayTimeoutMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
GatewayTimeoutMessageWithErrorf wraps an existing error while creating a new client message with a GatewayTimeout (504) return code
func (*Encoder) GatewayTimeoutMessagef ¶
GatewayTimeoutMessagef creates a new client message with a GatewayTimeout (504) return code
func (*Encoder) GatewayTimeoutWithError ¶
GatewayTimeoutWithError wraps an existing error while creating a new empty client message and a GatewayTimeout (504) return code
func (*Encoder) InternalServerError ¶
InternalServerError creates a new empty client message with a InternalServerError (500) return code
func (*Encoder) InternalServerErrorMessage ¶
InternalServerErrorMessage creates a new client message with a InternalServerError (500) return code
func (*Encoder) InternalServerErrorMessageWithError ¶
func (e *Encoder) InternalServerErrorMessageWithError(ctx context.Context, err error, message string) error
InternalServerErrorMessageWithError wraps an existing error while creating a new client message with a InternalServerError (500) return code
func (*Encoder) InternalServerErrorMessageWithErrorf ¶
func (e *Encoder) InternalServerErrorMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
InternalServerErrorMessageWithErrorf wraps an existing error while creating a new client message with a InternalServerError (500) return code
func (*Encoder) InternalServerErrorMessagef ¶
InternalServerErrorMessagef creates a new client message with a InternalServerError (500) return code
func (*Encoder) InternalServerErrorWithError ¶
InternalServerErrorWithError wraps an existing error while creating a new empty client message and a InternalServerError (500) return code
func (*Encoder) MethodNotAllowed ¶
MethodNotAllowed creates a new empty client message with a MethodNotAllowed (405) return code
func (*Encoder) MethodNotAllowedMessage ¶
MethodNotAllowedMessage creates a new client message with a MethodNotAllowed (405) return code
func (*Encoder) MethodNotAllowedMessageWithError ¶
func (e *Encoder) MethodNotAllowedMessageWithError(ctx context.Context, err error, message string) error
MethodNotAllowedMessageWithError wraps an existing error while creating a new client message with a MethodNotAllowed (405) return code
func (*Encoder) MethodNotAllowedMessageWithErrorf ¶
func (e *Encoder) MethodNotAllowedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
MethodNotAllowedMessageWithErrorf wraps an existing error while creating a new client message with a MethodNotAllowed (405) return code
func (*Encoder) MethodNotAllowedMessagef ¶
MethodNotAllowedMessagef creates a new client message with a MethodNotAllowed (405) return code
func (*Encoder) MethodNotAllowedWithError ¶
MethodNotAllowedWithError wraps an existing error while creating a new empty client message and a MethodNotAllowed (405) return code
func (*Encoder) NotAcceptable ¶
NotAcceptable creates a new empty client message with a NotAcceptable (406) return code
func (*Encoder) NotAcceptableMessage ¶
NotAcceptableMessage creates a new client message with a NotAcceptable (406) return code
func (*Encoder) NotAcceptableMessageWithError ¶
func (e *Encoder) NotAcceptableMessageWithError(ctx context.Context, err error, message string) error
NotAcceptableMessageWithError wraps an existing error while creating a new client message with a NotAcceptable (406) return code
func (*Encoder) NotAcceptableMessageWithErrorf ¶
func (e *Encoder) NotAcceptableMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
NotAcceptableMessageWithErrorf wraps an existing error while creating a new client message with a NotAcceptable (406) return code
func (*Encoder) NotAcceptableMessagef ¶
NotAcceptableMessagef creates a new client message with a NotAcceptable (406) return code
func (*Encoder) NotAcceptableWithError ¶
NotAcceptableWithError wraps an existing error while creating a new empty client message and a NotAcceptable (406) return code
func (*Encoder) NotFound ¶
NotFound creates a new empty client message with a NotFound (404) return code
func (*Encoder) NotFoundMessage ¶
NotFoundMessage creates a new client message with a NotFound (404) return code
func (*Encoder) NotFoundMessageWithError ¶
NotFoundMessageWithError wraps an existing error while creating a new client message with a NotFound (404) return code
func (*Encoder) NotFoundMessageWithErrorf ¶
func (e *Encoder) NotFoundMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
NotFoundMessageWithErrorf wraps an existing error while creating a new client message with a NotFound (404) return code
func (*Encoder) NotFoundMessagef ¶
NotFoundMessagef creates a new client message with a NotFound (404) return code
func (*Encoder) NotFoundWithError ¶
NotFoundWithError wraps an existing error while creating a new empty client message and a NotFound (404) return code
func (*Encoder) NotImplemented ¶
NotImplemented creates a new empty client message with a NotImplemented (501) return code
func (*Encoder) NotImplementedMessage ¶
NotImplementedMessage creates a new client message with a NotImplemented (501) return code
func (*Encoder) NotImplementedMessageWithError ¶
func (e *Encoder) NotImplementedMessageWithError(ctx context.Context, err error, message string) error
NotImplementedMessageWithError wraps an existing error while creating a new client message with a NotImplemented (501) return code
func (*Encoder) NotImplementedMessageWithErrorf ¶
func (e *Encoder) NotImplementedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
NotImplementedMessageWithErrorf wraps an existing error while creating a new client message with a NotImplemented (501) return code
func (*Encoder) NotImplementedMessagef ¶
NotImplementedMessagef creates a new client message with a NotImplemented (501) return code
func (*Encoder) NotImplementedWithError ¶
NotImplementedWithError wraps an existing error while creating a new empty client message and a NotImplemented (501) return code
func (*Encoder) RequestEntityTooLarge ¶
RequestEntityTooLarge creates a new empty client message with a RequestEntityTooLarge (413) return code
func (*Encoder) RequestEntityTooLargeMessage ¶
RequestEntityTooLargeMessage creates a new client message with a RequestEntityTooLarge (413) return code
func (*Encoder) RequestEntityTooLargeMessageWithError ¶
func (e *Encoder) RequestEntityTooLargeMessageWithError(ctx context.Context, err error, message string) error
RequestEntityTooLargeMessageWithError wraps an existing error while creating a new client message with a RequestEntityTooLarge (413) return code
func (*Encoder) RequestEntityTooLargeMessageWithErrorf ¶
func (e *Encoder) RequestEntityTooLargeMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
RequestEntityTooLargeMessageWithErrorf wraps an existing error while creating a new client message with a RequestEntityTooLarge (413) return code
func (*Encoder) RequestEntityTooLargeMessagef ¶
RequestEntityTooLargeMessagef creates a new client message with a RequestEntityTooLarge (413) return code
func (*Encoder) RequestEntityTooLargeWithError ¶
RequestEntityTooLargeWithError wraps an existing error while creating a new empty client message and a RequestEntityTooLarge (413) return code
func (*Encoder) RequestTimeout ¶
RequestTimeout creates a new empty client message with a RequestTimeout (408) return code
func (*Encoder) RequestTimeoutMessage ¶
RequestTimeoutMessage creates a new client message with a RequestTimeout (408) return code
func (*Encoder) RequestTimeoutMessageWithError ¶
func (e *Encoder) RequestTimeoutMessageWithError(ctx context.Context, err error, message string) error
RequestTimeoutMessageWithError wraps an existing error while creating a new client message with a RequestTimeout (408) return code
func (*Encoder) RequestTimeoutMessageWithErrorf ¶
func (e *Encoder) RequestTimeoutMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
RequestTimeoutMessageWithErrorf wraps an existing error while creating a new client message with a RequestTimeout (408) return code
func (*Encoder) RequestTimeoutMessagef ¶
RequestTimeoutMessagef creates a new client message with a RequestTimeout (408) return code
func (*Encoder) RequestTimeoutWithError ¶
RequestTimeoutWithError wraps an existing error while creating a new empty client message and a RequestTimeout (408) return code
func (*Encoder) ServiceUnavailable ¶
ServiceUnavailable creates a new empty client message with a ServiceUnavailable (503) return code
func (*Encoder) ServiceUnavailableMessage ¶
ServiceUnavailableMessage creates a new client message with a ServiceUnavailable (503) return code
func (*Encoder) ServiceUnavailableMessageWithError ¶
func (e *Encoder) ServiceUnavailableMessageWithError(ctx context.Context, err error, message string) error
ServiceUnavailableMessageWithError wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code
func (*Encoder) ServiceUnavailableMessageWithErrorf ¶
func (e *Encoder) ServiceUnavailableMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
ServiceUnavailableMessageWithErrorf wraps an existing error while creating a new client message with a ServiceUnavailable (503) return code
func (*Encoder) ServiceUnavailableMessagef ¶
ServiceUnavailableMessagef creates a new client message with a ServiceUnavailable (503) return code
func (*Encoder) ServiceUnavailableWithError ¶
ServiceUnavailableWithError wraps an existing error while creating a new empty client message and a ServiceUnavailable (503) return code
func (*Encoder) StatusCodeWithBody ¶
StatusCodeWithBody writes a statusCode and body
func (*Encoder) TooManyRequests ¶
TooManyRequests creates a new empty client message with a TooManyRequests (429) return code
func (*Encoder) TooManyRequestsMessage ¶
TooManyRequestsMessage creates a new client message with a TooManyRequests (429) return code
func (*Encoder) TooManyRequestsMessageWithError ¶
func (e *Encoder) TooManyRequestsMessageWithError(ctx context.Context, err error, message string) error
TooManyRequestsMessageWithError wraps an existing error while creating a new client message with a TooManyRequests (429) return code
func (*Encoder) TooManyRequestsMessageWithErrorf ¶
func (e *Encoder) TooManyRequestsMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
TooManyRequestsMessageWithErrorf wraps an existing error while creating a new client message with a TooManyRequests (429) return code
func (*Encoder) TooManyRequestsMessagef ¶
TooManyRequestsMessagef creates a new client message with a TooManyRequests (429) return code
func (*Encoder) TooManyRequestsWithError ¶
TooManyRequestsWithError wraps an existing error while creating a new empty client message and a TooManyRequests (429) return code
func (*Encoder) Unauthorized ¶
Unauthorized creates a new empty client message with a Unauthorized (401) return code
func (*Encoder) UnauthorizedMessage ¶
UnauthorizedMessage creates a new client message with a Unauthorized (401) return code
func (*Encoder) UnauthorizedMessageWithError ¶
func (e *Encoder) UnauthorizedMessageWithError(ctx context.Context, err error, message string) error
UnauthorizedMessageWithError wraps an existing error while creating a new client message with a Unauthorized (401) return code
func (*Encoder) UnauthorizedMessageWithErrorf ¶
func (e *Encoder) UnauthorizedMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
UnauthorizedMessageWithErrorf wraps an existing error while creating a new client message with a Unauthorized (401) return code
func (*Encoder) UnauthorizedMessagef ¶
UnauthorizedMessagef creates a new client message with a Unauthorized (401) return code
func (*Encoder) UnauthorizedWithError ¶
UnauthorizedWithError wraps an existing error while creating a new empty client message and a Unauthorized (401) return code
func (*Encoder) UnprocessableEntity ¶
UnprocessableEntity creates a new empty client message with a UnprocessableEntity (422) return code
func (*Encoder) UnprocessableEntityMessage ¶
UnprocessableEntityMessage creates a new client message with a UnprocessableEntity (422) return code
func (*Encoder) UnprocessableEntityMessageWithError ¶
func (e *Encoder) UnprocessableEntityMessageWithError(ctx context.Context, err error, message string) error
UnprocessableEntityMessageWithError wraps an existing error while creating a new client message with a UnprocessableEntity (422) return code
func (*Encoder) UnprocessableEntityMessageWithErrorf ¶
func (e *Encoder) UnprocessableEntityMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
UnprocessableEntityMessageWithErrorf wraps an existing error while creating a new client message with a UnprocessableEntity (422) return code
func (*Encoder) UnprocessableEntityMessagef ¶
UnprocessableEntityMessagef creates a new client message with a UnprocessableEntity (422) return code
func (*Encoder) UnprocessableEntityWithError ¶
UnprocessableEntityWithError wraps an existing error while creating a new empty client message and a UnprocessableEntity (422) return code
func (*Encoder) UnsupportedMediaType ¶
UnsupportedMediaType creates a new empty client message with a UnsupportedMediaType (415) return code
func (*Encoder) UnsupportedMediaTypeMessage ¶
UnsupportedMediaTypeMessage creates a new client message with a UnsupportedMediaType (415) return code
func (*Encoder) UnsupportedMediaTypeMessageWithError ¶
func (e *Encoder) UnsupportedMediaTypeMessageWithError(ctx context.Context, err error, message string) error
UnsupportedMediaTypeMessageWithError wraps an existing error while creating a new client message with a UnsupportedMediaType (415) return code
func (*Encoder) UnsupportedMediaTypeMessageWithErrorf ¶
func (e *Encoder) UnsupportedMediaTypeMessageWithErrorf(ctx context.Context, err error, format string, a ...any) error
UnsupportedMediaTypeMessageWithErrorf wraps an existing error while creating a new client message with a UnsupportedMediaType (415) return code
func (*Encoder) UnsupportedMediaTypeMessagef ¶
UnsupportedMediaTypeMessagef creates a new client message with a UnsupportedMediaType (415) return code
type HTTPEncoder ¶
type HTTPEncoder interface {
// Encode is the call that is made to encode data into a response body and returns an error if it fails
Encode(v interface{}) error
}
HTTPEncoder is an interface that is accepted when encoding http responses
type MessageResponse ¶
type MessageResponse struct {
Message string `json:"message,omitempty"`
TraceID string `json:"traceId,omitempty"`
}
MessageResponse holds a standard structure for http responses that carry a single message This also includes a trace ID for debugging purposes
type StructDecoder ¶
type StructDecoder[Request any] struct { // contains filtered or unexported fields }
StructDecoder decodes a JSON request body into a plain Request struct and validates it. The body is read once and must be a JSON object. Every key it names must reach a field of Request: a field with a json tag answers to that tag only; a field without one answers to its Go name, exactly or fully lower-cased. A key no field answers to is refused with 400 "invalid field in json - <key>", two keys reaching one field with 400 "json field name <field> collides with another field name of different case", and a JSON null with 400 "<key> cannot be null" unless the field is a pointer, which stays nil. A body that is not a JSON object answers 400 "failed to decode request body"; a value the field's type cannot hold, 400 "failed to unmarshal request body". With a validator (WithValidator), a PATCH validates only the fields the body carried (StructPartial, in struct order) and every other method validates the whole struct (Struct); a rejection answers 400 "failed validating the request". Every refusal is a ClientMessage, written by Encoder.ClientMessage.
A request body bound to a resource decodes with the resource package's decoders, which add what the generated struct tags declare (permissions, sizing, nullability, former names); a plain request body decodes here.
func NewStructDecoder ¶
func NewStructDecoder[Request any]() (*StructDecoder[Request], error)
NewStructDecoder creates a StructDecoder for Request, which must be a struct whose wire names are distinct.
func (*StructDecoder[Request]) Decode ¶
func (d *StructDecoder[Request]) Decode(request *http.Request) (*Request, error)
Decode decodes the request body into a new Request and validates it.
func (*StructDecoder[Request]) WithValidator ¶
func (d *StructDecoder[Request]) WithValidator(v ValidatorFunc) *StructDecoder[Request]
WithValidator returns a copy of the decoder that validates every decoded body with v.
type ValidatorFunc ¶
ValidatorFunc validates a struct, in whole (Struct) or in the named fields only (StructPartial). Each method returns an error when validation fails. A *validator.Validate from github.com/go-playground/validator satisfies it.