Documentation
¶
Index ¶
- Constants
- type Binder
- type Error
- func NewError(err error) *Error
- func NewForbiddenError(err ...validator.ValidationError) *Error
- func NewHTTPError(err *echo.HTTPError) *Error
- func NewInternalServerError() *Error
- func NewNotFoundError(err error) *Error
- func NewUnauthorizedError(err ...validator.ValidationError) *Error
- func NewValidationError(err ...validator.ValidationError) *Error
- type Fields
- type Logger
- type Responder
- type Response
Constants ¶
const ( TypeValidation = "validation-error" TypeForbidden = "forbidden" TypeNotFound = "data-not-found" TypeInternalServerError = "internal-server-error" TypeHTTP = "http-error" )
Error types for RFC-7807 Problem Details format. See: https://datatracker.ietf.org/doc/html/rfc7807
const ( TitleValidation = "Your request parameters didn't validate." TitleForbidden = "Your request has been forbidden." TitleNotFound = "Not Found" TitleInternalServerError = "Internal Server Error" )
Titles for RFC-7807 Problem Details format.
const ( StatusValidation = http.StatusBadRequest // 400 StatusForbidden = http.StatusForbidden // 403 StatusNotFound = http.StatusNotFound // 404 StatusBusinessError = http.StatusUnprocessableEntity // 422 StatusInternalServerError = http.StatusInternalServerError // 500 )
Statuses for RFC-7807 Problem Details format.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
type Error ¶
type Error struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail,omitempty"`
// InvalidParams contains the explanation of errors in RFC-7807 format.
InvalidParams validator.ValidationErrors `json:"invalid-params,omitempty"` //nolint
}
Error contains error in RFC-7807 Problem Details format.
func NewForbiddenError ¶
func NewForbiddenError(err ...validator.ValidationError) *Error
func NewHTTPError ¶
func NewInternalServerError ¶
func NewInternalServerError() *Error
func NewNotFoundError ¶
func NewUnauthorizedError ¶
func NewUnauthorizedError(err ...validator.ValidationError) *Error
func NewValidationError ¶
func NewValidationError(err ...validator.ValidationError) *Error
type Fields ¶ added in v0.2.6
type Fields map[string]interface{} // Maps string keys to values of any type, useful for flexible data structures
Fields is a generic key-value mapping structure Commonly used for dynamic data storage where field names are not known at compile time.
type Logger ¶
type Logger interface {
Error(args ...interface{})
}
Logger describes Error and Info functions.
type Responder ¶
type Responder struct {
// contains filtered or unexported fields
}
Responder wraps on echo Context to be used on echo HTTP handlers to construct an HTTP response.
func NewResponder ¶
NewResponder creates and returns pointer to Responder.
func (*Responder) ServeError ¶
ServeError sends a JSON error response with status code.
type Response ¶ added in v0.2.6
type Response struct {
Result interface{} `json:"result"` // The main data payload of the response, can be any type
Count int `json:"count,omitempty"` // Optional field indicating the number of items in result, omitted if zero
}
Response represents a standardized API response structure It's designed to be serialized as JSON and returned from API endpoints.