Documentation
¶
Index ¶
- func DomainInvariant(field, reason string) error
- func GRPCRateLimited(retryAfter time.Duration) error
- func HTTPStatus(code codes.Code) int
- func IsInvariant(err error) bool
- func StateInvariant(base error, field, reason string) error
- func TransitionInvariant(base error, field, reason string) error
- type ErrorResponse
- func Aborted() ErrorResponse
- func AlreadyExists() ErrorResponse
- func Canceled() ErrorResponse
- func Conflict(field, value string) 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 InvariantError
- type InvariantKind
- type Reason
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DomainInvariant ¶
func GRPCRateLimited ¶
GRPCRateLimited returns a ready gRPC error with RetryInfo + ErrorInfo(reason).
func HTTPStatus ¶
func IsInvariant ¶
func StateInvariant ¶
func TransitionInvariant ¶
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Code codes.Code `json:"code"`
Reason Reason `json:"reason,omitempty"`
Domain string `json:"domain,omitempty"` // optional service domain (for example "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 Canceled ¶
func Canceled() ErrorResponse
func Conflict ¶
func Conflict(field, value string) ErrorResponse
Conflict(field,value) -> 409/AlreadyExists.
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 adapts go-playground/validator errors into InvalidArgument + Violations. It attempts to resolve nested field path using StructNamespace() and falls back to Namespace() without root type.
func Internal ¶
func Internal() ErrorResponse
func InvalidArgument ¶
func InvalidArgument() ErrorResponse
func Newf ¶
func Newf(code codes.Code, reason, format string, a ...any) ErrorResponse
Newf is a formatted constructor with 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 with machine-friendly retry delay in milliseconds.
func ResourceExhausted ¶
func ResourceExhausted() ErrorResponse
func ToErrorResponse ¶
func ToErrorResponse(err error) ErrorResponse
ToErrorResponse converts any error into ErrorResponse (transport-agnostic). Supported inputs: - ErrorResponse / *ErrorResponse (direct passthrough) - context.Canceled / context.DeadlineExceeded - InvariantError (DomainInvariant/StateInvariant/TransitionInvariant)
func Unauthenticated ¶
func Unauthenticated() ErrorResponse
func Unauthorized ¶
func Unauthorized(scheme, realm string) ErrorResponse
Unauthorized with optional client hints.
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
Fast constructors for common cases.
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)
ToHTTPWithRetry sets Retry-After (seconds) and writes the error body.
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
type InvariantError ¶
type InvariantError struct {
Kind InvariantKind
Base error
Field string
Reason string
}
InvariantError is a unified type for field/state/transition invariant failures.
func (InvariantError) Error ¶
func (e InvariantError) Error() string
func (InvariantError) Unwrap ¶
func (e InvariantError) Unwrap() error
Unwrap enables errors.Is / errors.As.
type InvariantKind ¶
type InvariantKind string
InvariantKind classifies domain invariant failures.
const ( KindDomain InvariantKind = "domain" KindState InvariantKind = "state" KindTransition InvariantKind = "transition" )