Documentation
¶
Index ¶
- func GRPCRateLimited(retryAfter time.Duration) error
- func HTTPStatus(code codes.Code) int
- func IsDomainError(err error) bool
- type DomainError
- type DomainErrors
- type ErrorResponse
- func Aborted() ErrorResponse
- func AlreadyExists() ErrorResponse
- func Conflict(field, value string) ErrorResponse
- func ConvertDomainErrorsToValidation(errs DomainErrors) ErrorResponse
- func ConvertDomainToValidation(err error) ErrorResponse
- func DataLoss() ErrorResponse
- func DeadlineExceeded() ErrorResponse
- func FailedPrecondition() ErrorResponse
- func Forbidden(action, resource string) ErrorResponse
- func FromGRPC(err error) ErrorResponse
- func FromPlayground(err play.ValidationErrors, tagToReason map[string]string) ErrorResponse
- func Internal() ErrorResponse
- func InvalidArgument() ErrorResponse
- func New(message string, code codes.Code, details map[string]string) ErrorResponse
- func Newf(code codes.Code, reason, format string, a ...any) ErrorResponse
- func NotFound() ErrorResponse
- func NotFoundID(resource, id string) ErrorResponse
- func NotFoundWith(resourceKey, value string) ErrorResponse
- func OutOfRange() ErrorResponse
- func PermissionDenied() ErrorResponse
- func Precondition(reason string, details map[string]string) ErrorResponse
- func RateLimited(retryAfter time.Duration) ErrorResponse
- func ResourceExhausted() ErrorResponse
- func To(code codes.Code, reason, msg string) ErrorResponse
- func ToErrorResponse(err error) ErrorResponse
- func ToValidation(field, reason string) ErrorResponse
- func Unauthenticated() ErrorResponse
- func Unauthorized(scheme, realm string) ErrorResponse
- func Unavailable() ErrorResponse
- func Unimplemented() ErrorResponse
- func Unknown() ErrorResponse
- func Unsupported(name, value string) ErrorResponse
- func ValidationFields(fields map[string]string) ErrorResponse
- func ValidationViolations(v []FieldViolation) ErrorResponse
- func (e ErrorResponse) Error() string
- func (e ErrorResponse) ToGRPC() error
- func (e ErrorResponse) ToHTTP(w http.ResponseWriter)
- func (e ErrorResponse) ToHTTPWithRetry(w http.ResponseWriter, retryAfter time.Duration)
- func (e ErrorResponse) ToString() string
- func (e ErrorResponse) WithDetail(k, v string) ErrorResponse
- func (e ErrorResponse) WithDetails(m map[string]string) ErrorResponse
- func (e ErrorResponse) WithDomain(d string) ErrorResponse
- func (e ErrorResponse) WithReason(r string) ErrorResponse
- func (e ErrorResponse) WithViolations(v []FieldViolation) ErrorResponse
- type FieldViolation
- type Reason
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GRPCRateLimited ¶
GRPCRateLimited — готовый gRPC error с RetryInfo + ErrorInfo(reason).
func HTTPStatus ¶
func IsDomainError ¶
Types ¶
type DomainError ¶
одиночная доменная ошибка (инвариант)
func DomainInvariant ¶
func DomainInvariant(field, reason string) DomainError
func (DomainError) Error ¶
func (e DomainError) Error() string
type DomainErrors ¶
type DomainErrors []DomainError
батч доменных ошибок (несколько инвариантов за раз)
func (DomainErrors) Error ¶
func (es DomainErrors) Error() string
type ErrorResponse ¶
type ErrorResponse struct {
Code codes.Code `json:"code"`
Reason Reason `json:"reason,omitempty"`
Domain string `json:"domain,omitempty"` // опционально: заполняется сервисом (e.g. "auth-service")
Message string `json:"message"`
Details map[string]string `json:"details,omitempty"`
Violations []FieldViolation `json:"violations,omitempty"`
}
func Aborted ¶
func Aborted() ErrorResponse
func AlreadyExists ¶
func AlreadyExists() ErrorResponse
func Conflict ¶
func Conflict(field, value string) ErrorResponse
Conflict(field,value) -> 409/AlreadyExists.
func ConvertDomainErrorsToValidation ¶
func ConvertDomainErrorsToValidation(errs DomainErrors) ErrorResponse
func ConvertDomainToValidation ¶
func ConvertDomainToValidation(err error) ErrorResponse
func DataLoss ¶
func DataLoss() ErrorResponse
func DeadlineExceeded ¶
func DeadlineExceeded() ErrorResponse
func FailedPrecondition ¶
func FailedPrecondition() ErrorResponse
func FromGRPC ¶
func FromGRPC(err error) ErrorResponse
func FromPlayground ¶
func FromPlayground(err play.ValidationErrors, tagToReason map[string]string) ErrorResponse
FromPlayground — адаптер go-playground/validator -> InvalidArgument + Violations. Пытаемся получить вложенный путь поля: StructNamespace() -> (fallback) Namespace() без корня.
func Internal ¶
func Internal() ErrorResponse
func InvalidArgument ¶
func InvalidArgument() ErrorResponse
func Newf ¶
func Newf(code codes.Code, reason, format string, a ...any) ErrorResponse
Newf — форматированный конструктор с reason.
func NotFound ¶
func NotFound() ErrorResponse
func NotFoundWith ¶
func NotFoundWith(resourceKey, value string) ErrorResponse
func OutOfRange ¶
func OutOfRange() ErrorResponse
func PermissionDenied ¶
func PermissionDenied() ErrorResponse
func Precondition ¶
func Precondition(reason string, details map[string]string) ErrorResponse
Precondition(reason, details) -> 412/FailedPrecondition.
func RateLimited ¶
func RateLimited(retryAfter time.Duration) ErrorResponse
RateLimited — с machine-friendly задержкой в мс.
func ResourceExhausted ¶
func ResourceExhausted() ErrorResponse
func ToErrorResponse ¶
func ToErrorResponse(err error) ErrorResponse
ToErrorResponse — унифицирует любую ошибку до ErrorResponse (без привязки к транспорту).
func ToValidation ¶
func ToValidation(field, reason string) ErrorResponse
Хелперы, если нужно точечно.
func Unauthenticated ¶
func Unauthenticated() ErrorResponse
func Unauthorized ¶
func Unauthorized(scheme, realm string) ErrorResponse
Unauthorized с подсказками для клиента.
func Unavailable ¶
func Unavailable() ErrorResponse
func Unimplemented ¶
func Unimplemented() ErrorResponse
func Unsupported ¶
func Unsupported(name, value string) ErrorResponse
func ValidationFields ¶
func ValidationFields(fields map[string]string) ErrorResponse
Быстрые конструкторы частых кейсов
func ValidationViolations ¶
func ValidationViolations(v []FieldViolation) ErrorResponse
func (ErrorResponse) Error ¶
func (e ErrorResponse) Error() string
func (ErrorResponse) ToGRPC ¶
func (e ErrorResponse) ToGRPC() error
func (ErrorResponse) ToHTTP ¶
func (e ErrorResponse) ToHTTP(w http.ResponseWriter)
func (ErrorResponse) ToHTTPWithRetry ¶
func (e ErrorResponse) ToHTTPWithRetry(w http.ResponseWriter, retryAfter time.Duration)
Helper: добавить Retry-After (сек) и вернуть тело ошибки.
func (ErrorResponse) ToString ¶
func (e ErrorResponse) ToString() string
func (ErrorResponse) WithDetail ¶
func (e ErrorResponse) WithDetail(k, v string) ErrorResponse
func (ErrorResponse) WithDetails ¶
func (e ErrorResponse) WithDetails(m map[string]string) ErrorResponse
func (ErrorResponse) WithDomain ¶
func (e ErrorResponse) WithDomain(d string) ErrorResponse
func (ErrorResponse) WithReason ¶
func (e ErrorResponse) WithReason(r string) ErrorResponse
func (ErrorResponse) WithViolations ¶
func (e ErrorResponse) WithViolations(v []FieldViolation) ErrorResponse
type FieldViolation ¶
type FieldViolation struct {
Field string `json:"field"`
Reason string `json:"reason,omitempty"`
Description string `json:"description,omitempty"`
}
func ViolationsFromMap ¶
func ViolationsFromMap(m map[string]string) []FieldViolation