Versions in this module Expand all Collapse all v0 v0.2.0 Nov 14, 2025 Changes in this version + const DefaultLimit + const DefaultPage + const MaxLimit + var ErrDatabaseConnection = errors.New("database connection failed") + var ErrDatabaseQuery = errors.New("database query failed") + var ErrDatabaseTransaction = errors.New("database transaction failed") + var ErrDuplicateRecord = errors.New("duplicate record") + var ErrEmptyToken = errors.New("empty token") + var ErrExternalServiceError = errors.New("external service error") + var ErrExternalServiceTimeout = errors.New("external service timeout") + var ErrExternalServiceUnavailable = errors.New("external service unavailable") + var ErrForbidden = errors.New("forbidden") + var ErrInsufficientInventory = errors.New("insufficient inventory") + var ErrInsufficientPermissions = errors.New("insufficient permissions") + var ErrInvalidAuthorizationFormat = errors.New("invalid authorization format, expected 'Bearer <token>'") + var ErrInvalidFormat = errors.New("invalid format") + var ErrInvalidInput = errors.New("invalid input") + var ErrInvalidOrderStatus = errors.New("invalid order status") + var ErrInvalidPrice = errors.New("invalid price") + var ErrInvalidQuantity = errors.New("invalid quantity") + var ErrInvalidToken = errors.New("invalid token") + var ErrMissingAuthorizationHeader = errors.New("missing authorization header") + var ErrMissingRequiredField = errors.New("missing required field") + var ErrMissingToken = errors.New("missing token") + var ErrRecordNotFound = errors.New("record not found") + var ErrResourceAccessDenied = errors.New("resource access denied") + var ErrResourceNotFound = errors.New("resource not found") + var ErrTokenExpired = errors.New("token expired") + var ErrUnauthorized = errors.New("unauthorized") + func AsError(err error, target interface{}) bool + func BadRequest(c *gin.Context, code, message string, details map[string]interface{}) + func Created(c *gin.Context, data interface{}, meta *ResponseMeta) + func Error(c *gin.Context, statusCode int, code, message string, ...) + func Forbidden(c *gin.Context, code, message string, details map[string]interface{}) + func GetOrganizationID(c *gin.Context) (string, bool) + func GetStatusCode(err error) int + func GetSubjectID(c *gin.Context) (string, bool) + func GetTraceID(c *gin.Context) string + func GetUserRoles(c *gin.Context) ([]string, bool) + func InternalServerError(c *gin.Context, code, message string, details map[string]interface{}) + func IsAdmin(c *gin.Context) bool + func IsError(err error, target error) bool + func NotFound(c *gin.Context, code, message string, details map[string]interface{}) + func Retry(ctx context.Context, config *RetryConfig, operation RetryableOperation) error + func RetryWithResult[T any](ctx context.Context, config *RetryConfig, ...) (T, error) + func Success(c *gin.Context, data interface{}, meta *ResponseMeta) + func Unauthorized(c *gin.Context, code, message string, details map[string]interface{}) + type AppError struct + Cause error + Code ErrorCode + Context map[string]interface{} + Details string + Fields map[string]string + Message string + StatusCode int + func IsAppError(err error) (*AppError, bool) + func NewAppError(code ErrorCode, message string, statusCode int) *AppError + func NewBusinessRuleError(rule string, details string) *AppError + func NewDatabaseError(operation string, cause error) *AppError + func NewETagMismatchError(expected, actual string) *AppError + func NewExternalServiceError(service string, cause error) *AppError + func NewForbiddenError(message string) *AppError + func NewIdempotencyConflictError(message string) *AppError + func NewInternalError(message string) *AppError + func NewNotFoundError(resource string) *AppError + func NewOptimisticLockConflictError(message string) *AppError + func NewPreconditionFailedError(message string) *AppError + func NewUnauthorizedError(message string) *AppError + func NewValidationError(message string) *AppError + func NewVersionConflictError(expected, actual int64) *AppError + func WrapError(err error, code ErrorCode, message string, statusCode int) *AppError + func (e *AppError) Error() string + func (e *AppError) Unwrap() error + func (e *AppError) WithCause(cause error) *AppError + func (e *AppError) WithContext(key string, value interface{}) *AppError + func (e *AppError) WithField(field, message string) *AppError + type CircuitBreaker struct + func NewCircuitBreaker(config *CircuitBreakerConfig) *CircuitBreaker + func (cb *CircuitBreaker) Execute(ctx context.Context, operation RetryableOperation) error + func (cb *CircuitBreaker) GetState() CircuitBreakerState + func (cb *CircuitBreaker) Reset() + type CircuitBreakerConfig struct + FailureThreshold int + MaxRequests int + RecoveryTimeout time.Duration + type CircuitBreakerState int + const CircuitBreakerClosed + const CircuitBreakerHalfOpen + const CircuitBreakerOpen + type ConflictError struct + Details map[string]interface{} + Message string + Type string + func (e *ConflictError) Error() string + func (e *ConflictError) ToAppError() *AppError + type DefaultLogger struct + func (l *DefaultLogger) Error(msg string, fields ...interface{}) + func (l *DefaultLogger) Info(msg string, fields ...interface{}) + func (l *DefaultLogger) Warn(msg string, fields ...interface{}) + type ErrorCode string + const ErrorCodeAccessDenied + const ErrorCodeBusinessRuleViolation + const ErrorCodeConfigError + const ErrorCodeDatabaseError + const ErrorCodeDuplicateRecord + const ErrorCodeETagMismatch + const ErrorCodeExternalServiceError + const ErrorCodeForbidden + const ErrorCodeIdempotencyConflict + const ErrorCodeInsufficientInventory + const ErrorCodeInsufficientPerms + const ErrorCodeInternalError + const ErrorCodeInvalidAuth + const ErrorCodeInvalidFormat + const ErrorCodeInvalidInput + const ErrorCodeInvalidOrderStatus + const ErrorCodeInvalidPrice + const ErrorCodeInvalidQuantity + const ErrorCodeMissingAuth + const ErrorCodeMissingField + const ErrorCodeOptimisticLockConflict + const ErrorCodePreconditionFailed + const ErrorCodeRecordNotFound + const ErrorCodeResourceNotFound + const ErrorCodeServiceTimeout + const ErrorCodeServiceUnavailable + const ErrorCodeTokenExpired + const ErrorCodeTransactionFailed + const ErrorCodeUnauthorized + const ErrorCodeValidationFailed + const ErrorCodeVersionConflict + func GetErrorCode(err error) ErrorCode + type ErrorHandler struct + func NewErrorHandler(logger Logger) *ErrorHandler + func (h *ErrorHandler) ErrorMiddleware() gin.HandlerFunc + func (h *ErrorHandler) HandleError(c *gin.Context, err error) + func (h *ErrorHandler) HandlePanic(c *gin.Context, recovered interface{}) + func (h *ErrorHandler) HandleValidationError(c *gin.Context, validationErr *ValidationErrors) + func (h *ErrorHandler) RecoveryMiddleware() gin.HandlerFunc + type ErrorWithContext struct + Context map[string]interface{} + Err error + func NewErrorWithContext(err error, context map[string]interface{}) *ErrorWithContext + func (e *ErrorWithContext) Error() string + func (e *ErrorWithContext) Unwrap() error + type FilterParams struct + Category string + DateFrom string + DateTo string + Extra map[string]string + IsActive *bool + OrgID string + Search string + func GetFilterParams(c *gin.Context) *FilterParams + type IdempotencyManager struct + func NewIdempotencyManager() *IdempotencyManager + func (m *IdempotencyManager) ExtractIdempotencyKey(c *gin.Context) (string, bool) + func (m *IdempotencyManager) IsIdempotentRequest(c *gin.Context) bool + type Logger interface + Error func(msg string, fields ...interface{}) + Info func(msg string, fields ...interface{}) + Warn func(msg string, fields ...interface{}) + type OptimisticLockError struct + CurrentETag string + CurrentVersion int64 + EntityID string + ExpectedETag string + LastModified time.Time + func NewOptimisticLockError(entityID, expectedETag, currentETag string, currentVersion int64, ...) *OptimisticLockError + func (e *OptimisticLockError) Error() string + func (e *OptimisticLockError) ToAppError() *AppError + type OptimisticLockManager struct + func NewOptimisticLockManager() *OptimisticLockManager + func (m *OptimisticLockManager) ExtractETagFromContext(c *gin.Context) (string, bool) + func (m *OptimisticLockManager) ExtractVersionFromContext(c *gin.Context) (int64, bool) + func (m *OptimisticLockManager) PrepareForUpdate(entity VersionedEntity) + func (m *OptimisticLockManager) ValidateETag(entity VersionedEntity, expectedETag, currentETag string) error + func (m *OptimisticLockManager) ValidateVersion(entity VersionedEntity, expectedVersion int64) error + type PaginationMeta struct + HasNext bool + HasPrev bool + Limit int + Page int + Total int + TotalPages int + func NewPaginationMeta(page, limit, total int) *PaginationMeta + type PaginationParams struct + Limit int + Page int + func GetPaginationParams(c *gin.Context) *PaginationParams + func (p *PaginationParams) CalculateOffset() int + func (p *PaginationParams) Validate() error + type PaginationRequest struct + Limit int + Offset int + type Response struct + Data interface{} + Error *ResponseError + Meta *ResponseMeta + func BuildPaginationResponse(data interface{}, total int, params *PaginationParams) *Response + type ResponseError struct + Code string + Details map[string]interface{} + Message string + type ResponseMeta struct + Extra map[string]interface{} + Pagination *PaginationMeta + Timestamp string + TraceID string + type RetryConfig struct + BackoffFactor float64 + InitialDelay time.Duration + Jitter bool + MaxAttempts int + MaxDelay time.Duration + RetryableErrors []error + func DefaultRetryConfig() *RetryConfig + type RetryableOperation func(ctx context.Context, attempt int) error + type SortParams struct + SortBy string + SortOrder string + func GetSortParams(c *gin.Context) *SortParams + type ValidationErrors struct + Errors map[string]string + func NewValidationErrors() *ValidationErrors + func (v *ValidationErrors) Add(field, message string) + func (v *ValidationErrors) Error() string + func (v *ValidationErrors) HasErrors() bool + func (v *ValidationErrors) ToAppError() *AppError + type VersionedEntity interface + GetID func() string + GetUpdatedAt func() time.Time + GetVersion func() int64 + IncrementVersion func()