restflex

package module
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

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

func DecodeJSON(body io.Reader, o any) error

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

func NewHandlerWithContext(l infra.Logger, h httpx.HandlerWithContext) http.Handler

func NewValidationError

func NewValidationError(statusCode int, cause error, messages ...string) error

NewValidationError is called when a data validation error occurs.

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 NewAPIError

func NewAPIError(statusCode int, cause error, messages ...string) APIError

func NewBadRequest

func NewBadRequest(messages ...string) APIError

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
}

Jump to

Keyboard shortcuts

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