Documentation
¶
Index ¶
- Variables
- func DecodeJSON(body io.Reader, o any) error
- func EncodeJSON(w http.ResponseWriter, msg any) error
- func NewHandlerWithContext(l infra.Logger, h httpx.HandlerWithContext) http.Handler
- func NewValidationError(statusCode int, cause error, messages ...string) error
- type APIError
- type ErrorMessage
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAuth = NewAPIError(http.StatusUnauthorized, nil, "authorization required") ErrNotFound = NewAPIError(http.StatusNotFound, nil, "item not found") ErrInvalidRequestBody = NewAPIError(http.StatusBadRequest, nil, "expecting well formed request body") ErrBadRequest = NewBadRequest(http.StatusText(http.StatusBadRequest)) ErrInternal = NewAPIError(http.StatusInternalServerError, nil, "internal server error") )
Functions ¶
func DecodeJSON ¶
DecodeJSON reads a JSON message from HTTP request.
func EncodeJSON ¶
func EncodeJSON(w http.ResponseWriter, msg any) error
EncodeJSON encodes a JSON message to HTTP response.
func NewHandlerWithContext ¶
Types ¶
type APIError ¶
type APIError interface {
error
// StatusCode returns HTTP status code.
StatusCode() int
// Unwrap returns the underlying cause for this APIError if any.
Unwrap() error
// Errors returns an API compatible list of error messages.
Errors() []string
}
func NewBadRequest ¶
type ErrorMessage ¶
type ErrorMessage struct {
Errors []string `json:"errors"`
}
ErrorMessage is JSON formatted error message targetted to be consumed by machine.
func NewErrorMessage ¶
func NewErrorMessage(errors ...string) *ErrorMessage
type ValidationError ¶
type ValidationError interface {
ValidationError() string
}
Click to show internal directories.
Click to hide internal directories.