Documentation
¶
Index ¶
- Variables
- func AddValidationErrorMessage(tag string, messageFunc ValidationErrorMessageFunc)
- func AddValidationErrorMessages(errors map[string]ValidationErrorMessageFunc)
- func NewHTTPErrorFromError(httpCode int, err error, frontendMessage ...string) error
- func NewHTTPErrorFromMessage(httpCode int, message string, frontendMessage ...string) error
- type HttpError
- type HttpErrorField
- type HttpErrorResponse
- type HttpResponse
- type HttpResponseParamsCb
- type ValidationErrorMessageFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = NewHTTPErrorFromMessage(http.StatusNotFound, "not found") 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 ¶
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) GetHttpStatusCode ¶
func (HttpError) GetMessage ¶
type HttpErrorField ¶
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
Click to show internal directories.
Click to hide internal directories.