casual

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound            = NewHTTPErrorFromMessage(http.StatusNotFound, "not found")
	ErrUnauthorized        = NewHTTPErrorFromMessage(http.StatusUnauthorized, "unauthorized")
	ErrInternalServerError = NewHTTPErrorFromMessage(http.StatusInternalServerError, "internal server error")
	ErrTooManyRequests     = NewHTTPErrorFromMessage(http.StatusTooManyRequests, "too many requests")
	ErrBadRequest          = NewHTTPErrorFromMessage(http.StatusBadRequest, "bad request")
	ErrUnprocessableEntity = NewHTTPErrorFromMessage(http.StatusUnprocessableEntity, "unprocessable entity")
)

Functions

func AddValidationErrorMessage

func AddValidationErrorMessage(tag string, messageFunc ValidationErrorMessageFunc)

func AddValidationErrorMessages

func AddValidationErrorMessages(errors map[string]ValidationErrorMessageFunc)

func NewHTTPErrorFromError

func NewHTTPErrorFromError(httpCode int, err error, frontendMessage ...string) error

func NewHTTPErrorFromMessage

func NewHTTPErrorFromMessage(httpCode int, message string, frontendMessage ...string) error

Types

type HttpError

type HttpError struct {
	Code    any    `json:"code,omitempty" xml:"code,omitempty"`
	Message string `json:"message" xml:"message"`

	Details []*HttpErrorField `json:"details,omitempty" xml:"details,omitempty"`
	// contains filtered or unexported fields
}

func (HttpError) GetCode

func (e HttpError) GetCode() any

func (HttpError) GetHttpStatusCode

func (e HttpError) GetHttpStatusCode() int

func (HttpError) GetMessage

func (e HttpError) GetMessage() string

type HttpErrorField

type HttpErrorField struct {
	Field string `json:"field" xml:"field"`
	Issue string `json:"issue" xml:"issue"`
}

type HttpErrorResponse

type HttpErrorResponse struct {
	Status int                    `json:"status" xml:"status"`
	Error  *HttpError             `json:"error" xml:"error"`
	Meta   map[string]interface{} `json:"meta,omitempty" xml:"meta,omitempty"`
}

func NewHttpErrorResponse

func NewHttpErrorResponse(err error, opts ...HttpResponseParamsCb) (int, *HttpErrorResponse)

type HttpResponse

type HttpResponse[T any] struct {
	Status int                    `json:"status" xml:"status"`
	Data   *T                     `json:"data,omitempty" xml:"data,omitempty"`
	Meta   map[string]interface{} `json:"meta,omitempty" xml:"meta,omitempty"`
}

func NewHTTPResponse

func NewHTTPResponse[T any](data *T, opts ...HttpResponseParamsCb) (int, *HttpResponse[T])

type HttpResponseParamsCb

type HttpResponseParamsCb func(params *httpResponseParams)

func WithHttpStatusCode

func WithHttpStatusCode(code int) HttpResponseParamsCb

func WithLang

func WithLang(lang string) HttpResponseParamsCb

func WithMeta

func WithMeta(meta map[string]interface{}) HttpResponseParamsCb

type ValidationErrorMessageFunc

type ValidationErrorMessageFunc func(lang *string, fe validator.FieldError) string

func DefaultValidationErrorMessageFunc

func DefaultValidationErrorMessageFunc(message string) ValidationErrorMessageFunc

Jump to

Keyboard shortcuts

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