Versions in this module Expand all Collapse all v0 v0.1.9 Mar 19, 2026 v0.1.8 Mar 15, 2026 v0.1.7 Mar 2, 2026 v0.1.6 Feb 19, 2026 v0.1.5 Feb 10, 2026 v0.1.4 Feb 3, 2026 v0.1.3 Feb 1, 2026 v0.1.2 Jan 25, 2026 v0.1.1 Jan 19, 2026 v0.1.0 Jan 17, 2026 Changes in this version + var DefaultFactory = NewErrorFactory("croupier") + func AddCustomErrorConfig(config ErrorConfig) + func GetAllErrorConfigs() map[ErrorCode]ErrorConfig + func GetHTTPStatusCode(code ErrorCode) int + func IsRetryable(code ErrorCode) bool + func IsUserError(code ErrorCode) bool + func ResponseMiddleware(next http.Handler) http.Handler + func SendError(w http.ResponseWriter, r *http.Request, err error) + func SendPaginated(w http.ResponseWriter, r *http.Request, data interface{}, ...) + func SendPaginatedWithMetadata(w http.ResponseWriter, r *http.Request, data interface{}, ...) + func SendSuccess(w http.ResponseWriter, r *http.Request, data interface{}) + type APIResponse struct + Data T + Error *ErrorInfo + Metadata *Metadata + RequestID string + Success bool + Timestamp time.Time + Type ResponseType + func ErrorResponse(err error) *APIResponse[any] + func PaginatedResponse[T any](data T, pagination *Pagination) *APIResponse[T] + func SuccessResponse[T any](data T) *APIResponse[T] + type AppError struct + Category ErrorCategory + Cause error + Code ErrorCode + Context map[string]interface{} + Details string + HTTPHeaders map[string]string + HTTPStatusCode int + Message string + Operation string + RetryCount int + RetryDelay time.Duration + Retryable bool + Severity ErrorSeverity + Timestamp time.Time + TraceID string + UserError bool + func GameNotFoundError(operation, gameID string) *AppError + func InternalError(operation string, cause error) *AppError + func InvalidInputError(operation string, field, value string, cause error) *AppError + func New(code ErrorCode, operation string, cause error) *AppError + func Newf(code ErrorCode, operation string, cause error, format string, ...) *AppError + func NotFoundError(operation, resourceType, resourceID string) *AppError + func Wrap(cause error, operation string) *AppError + func (e *AppError) Error() string + func (e *AppError) Is(target error) bool + func (e *AppError) String() string + func (e *AppError) ToJSON() map[string]interface{} + func (e *AppError) Unwrap() error + func (e *AppError) WithContext(key string, value interface{}) *AppError + func (e *AppError) WithDetails(details string) *AppError + func (e *AppError) WithHTTPHeader(key, value string) *AppError + func (e *AppError) WithRetry(delay time.Duration, count int) *AppError + type DefaultMetricsCollector struct + func NewDefaultMetricsCollector() *DefaultMetricsCollector + func (dmc *DefaultMetricsCollector) GetErrorCounts() map[ErrorCode]int64 + func (dmc *DefaultMetricsCollector) GetErrorDurations() map[ErrorCode]time.Duration + func (dmc *DefaultMetricsCollector) GetRequestCounts() map[string]int64 + func (dmc *DefaultMetricsCollector) IncrementErrorCount(code ErrorCode, severity ErrorSeverity, category ErrorCategory) + func (dmc *DefaultMetricsCollector) IncrementHTTPRequestCount(method, path, statusCode string) + func (dmc *DefaultMetricsCollector) RecordErrorDuration(code ErrorCode, duration time.Duration) + func (dmc *DefaultMetricsCollector) RecordHTTPRequestDuration(method, path string, duration time.Duration) + func (dmc *DefaultMetricsCollector) Reset() + func (dmc *DefaultMetricsCollector) ToJSON() []byte + type DefaultTraceGenerator struct + func (d *DefaultTraceGenerator) GenerateTraceID() string + type ErrorAnalyzer struct + func NewErrorAnalyzer(maxErrors int, collector MetricsCollector) *ErrorAnalyzer + func (ea *ErrorAnalyzer) AddError(err *AppError) + func (ea *ErrorAnalyzer) Clear() + func (ea *ErrorAnalyzer) GetStats() *ErrorStats + func (ea *ErrorAnalyzer) GetTopErrors(limit int) []ErrorCode + type ErrorCategory string + const CategoryAuth + const CategoryBusiness + const CategoryDatabase + const CategoryExternal + const CategoryNetwork + const CategoryPermission + const CategorySystem + const CategoryValidation + type ErrorCode string + const ErrCodeConflict + const ErrCodeConnectionLost + const ErrCodeConnectionTimeout + const ErrCodeDatabaseError + const ErrCodeForbidden + const ErrCodeGameAlreadyExist + const ErrCodeGameDisabled + const ErrCodeGameNotFound + const ErrCodeInsufficientPermissions + const ErrCodeInternal + const ErrCodeInvalidCredentials + const ErrCodeInvalidGameStatus + const ErrCodeInvalidInput + const ErrCodeInvalidToken + const ErrCodeNetworkError + const ErrCodeNotFound + const ErrCodeRateLimit + const ErrCodeServiceUnavailable + const ErrCodeTimeout + const ErrCodeTokenExpired + const ErrCodeTransactionFailed + const ErrCodeUnauthorized + type ErrorCollection struct + Errors []*AppError + Total int + func (ec *ErrorCollection) Add(err *AppError) + func (ec *ErrorCollection) Error() string + func (ec *ErrorCollection) First() *AppError + func (ec *ErrorCollection) GetByCode(code ErrorCode) []*AppError + func (ec *ErrorCollection) GetBySeverity(severity ErrorSeverity) []*AppError + func (ec *ErrorCollection) HasErrors() bool + func (ec *ErrorCollection) Is(target error) bool + type ErrorConfig struct + Category ErrorCategory + Code ErrorCode + DefaultDetails string + HTTPStatusCode int + Message string + Retryable bool + Severity ErrorSeverity + UserError bool + func GetErrorConfig(code ErrorCode) (ErrorConfig, error) + type ErrorFactory struct + func NewErrorFactory(serviceName string) *ErrorFactory + func (f *ErrorFactory) ConflictError(operation string, resource string, cause error) *AppError + func (f *ErrorFactory) DatabaseError(operation string, query string, cause error) *AppError + func (f *ErrorFactory) ForbiddenError(operation string, resource string, cause error) *AppError + func (f *ErrorFactory) GameAlreadyExistError(operation, gameName string) *AppError + func (f *ErrorFactory) GameDisabledError(operation, gameID string) *AppError + func (f *ErrorFactory) GameNotFoundError(operation, gameID string) *AppError + func (f *ErrorFactory) InternalError(operation string, cause error) *AppError + func (f *ErrorFactory) InternalErrorf(operation string, cause error, format string, args ...interface{}) *AppError + func (f *ErrorFactory) InvalidInputError(operation string, field, value string, cause error) *AppError + func (f *ErrorFactory) NetworkError(operation string, endpoint string, cause error) *AppError + func (f *ErrorFactory) New(code ErrorCode, operation string, cause error) *AppError + func (f *ErrorFactory) NewWithDetails(code ErrorCode, operation string, details string, cause error) *AppError + func (f *ErrorFactory) Newf(code ErrorCode, operation string, cause error, format string, ...) *AppError + func (f *ErrorFactory) NotFoundError(operation, resourceType, resourceID string) *AppError + func (f *ErrorFactory) RateLimitError(operation string, limit int, window time.Duration) *AppError + func (f *ErrorFactory) ServiceUnavailableError(operation, service string, cause error) *AppError + func (f *ErrorFactory) TimeoutError(operation string, timeout time.Duration, cause error) *AppError + func (f *ErrorFactory) UnauthorizedError(operation string, cause error) *AppError + func (f *ErrorFactory) WithTraceGenerator(generator TraceGenerator) *ErrorFactory + func (f *ErrorFactory) Wrap(cause error, operation string) *AppError + func (f *ErrorFactory) Wrapf(cause error, operation string, format string, args ...interface{}) *AppError + type ErrorInfo struct + Code ErrorCode + Context map[string]interface{} + Details string + Message string + Operation string + RetryDelay *time.Duration + Retryable bool + Severity ErrorSeverity + TraceID string + type ErrorLogger struct + func NewErrorLogger(serviceName, version string, enableJSON bool) *ErrorLogger + func (el *ErrorLogger) LogError(err *AppError, context map[string]interface{}) + func (el *ErrorLogger) LogErrorWithMetrics(err *AppError, context map[string]interface{}, ...) + func (el *ErrorLogger) LogPanic(recovered interface{}, context map[string]interface{}) + type ErrorMetrics struct + Code ErrorCode + Count int64 + Duration time.Duration + FirstSeen time.Time + LastSeen time.Time + Operation string + Severity ErrorSeverity + type ErrorSeverity string + const SeverityCritical + const SeverityHigh + const SeverityLow + const SeverityMedium + func GetSeverity(code ErrorCode) ErrorSeverity + type ErrorStats struct + ErrorsByCategory map[ErrorCategory]int64 + ErrorsByCode map[ErrorCode]int64 + ErrorsBySeverity map[ErrorSeverity]int64 + RecentErrors []*AppError + TimeRange TimeRange + TotalErrors int64 + type LogLevel string + const LogLevelDebug + const LogLevelError + const LogLevelInfo + const LogLevelWarn + type Metadata struct + Duration time.Duration + Pagination *Pagination + Performance *Performance + RequestID string + Timestamp time.Time + Version string + type MetricsCollector interface + IncrementErrorCount func(code ErrorCode, severity ErrorSeverity, category ErrorCategory) + IncrementHTTPRequestCount func(method, path, statusCode string) + RecordErrorDuration func(code ErrorCode, duration time.Duration) + RecordHTTPRequestDuration func(method, path string, duration time.Duration) + type Pagination struct + HasNext bool + HasPrev bool + Page int + PageSize int + Total int64 + TotalPages int + type Performance struct + CacheHits int + CacheMisses int + DatabaseQueries int + DatabaseTime time.Duration + ExternalCalls int + ExternalTime time.Duration + type ResponseBuilder struct + func NewResponseBuilder[T any]() *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) Build() *APIResponse[T] + func (rb *ResponseBuilder[T]) Error(err error) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) Success(data T) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) WithMetadata(metadata *Metadata) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) WithPagination(pagination *Pagination) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) WithPerformance(performance *Performance) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) WithRequestID(requestID string) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) WithVersion(version string) *ResponseBuilder[T] + func (rb *ResponseBuilder[T]) WriteJSON(w http.ResponseWriter, r *http.Request) + type ResponseType string + const ResponseTypeError + const ResponseTypeSuccess + type TimeRange struct + End time.Time + Start time.Time + type TraceGenerator interface + GenerateTraceID func() string