problemdetails

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeValidation          = "validation-error"
	TypeUnauthorized        = "unauthorized"
	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

View Source
const (
	TitleValidation          = "Your request parameters didn't validate."
	TitleUnauthorized        = "Your request has not been applied."
	TitleForbidden           = "Your request has been forbidden."
	TitleNotFound            = "Not Found"
	TitleInternalServerError = "Internal Server Error"
)

Titles for RFC-7807 Problem Details format.

View Source
const (
	StatusValidation          = http.StatusBadRequest          // 400
	StatusUnauthorized        = http.StatusUnauthorized        // 401
	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
}

func NewBinder

func NewBinder(l Logger) *Binder

NewBinder creates and returns new Binder instance.

func (*Binder) Bind

func (b *Binder) Bind(c echo.Context, req interface{}) error

Bind parses echo Context to data structure. Returns en error if data is invalid.

func (*Binder) BindAndValidate

func (b *Binder) BindAndValidate(c echo.Context, req interface{}) error

BindAndValidate parses echo Context to data structure and validate received data. Returns en error if data is invalid.

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 NewError

func NewError(err error) *Error

func NewForbiddenError

func NewForbiddenError(err ...validator.ValidationError) *Error

func NewHTTPError

func NewHTTPError(err *echo.HTTPError) *Error

func NewInternalServerError

func NewInternalServerError() *Error

func NewNotFoundError

func NewNotFoundError(err error) *Error

func NewUnauthorizedError

func NewUnauthorizedError(err ...validator.ValidationError) *Error

func NewValidationError

func NewValidationError(err ...validator.ValidationError) *Error

func (*Error) Error

func (e *Error) Error() string

Error represents an error condition, with the nil value representing no 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

func NewResponder(l Logger) *Responder

NewResponder creates and returns pointer to Responder.

func (*Responder) ServeError

func (r *Responder) ServeError(c echo.Context, err error, logPrefix ...string) error

ServeError sends a JSON error response with status code.

func (*Responder) ServeResult

func (r *Responder) ServeResult(c echo.Context, i interface{}) error

ServeResult sends a JSON response with the result data.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL