Documentation
¶
Index ¶
- Variables
- func IsAlreadyRedeemed(err error) bool
- func IsDatabaseError(err error) bool
- func IsNotFound(err error) bool
- func IsRateLimited(err error) bool
- func IsUnavailable(err error) bool
- func IsValidationError(err error) bool
- type DatabaseError
- type ReportParams
- type ReportType
- type Repository
- type User
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUserNotFound indicates that the requested user email was not found in the database ErrUserNotFound = errors.New("user email not found in database") ErrDatabaseUnavailable = errors.New("database is temporarily unavailable, try later") // ErrInvalidEmail indicates the provided email has invalid format ErrInvalidEmail = errors.New("invalid email format") // ErrRateLimitExceeded indicates a user has made too many requests ErrRateLimitExceeded = errors.New("rate limit exceeded") // ErrAlreadyRedeemed indicates a user has already redeemed their cocktail ErrAlreadyRedeemed = errors.New("cocktail already redeemed") // ErrInvalidCredentials indicates invalid authentication credentials ErrInvalidCredentials = errors.New("invalid credentials") // ErrInternalServer indicates a generic internal server error ErrInternalServer = errors.New("internal server error") )
Standard domain errors - these are sentinel error values that can be compared directly
Functions ¶
func IsAlreadyRedeemed ¶
IsAlreadyRedeemed returns true if the error indicates already redeemed status
func IsDatabaseError ¶
IsDatabaseError returns true if the error is a database error
func IsNotFound ¶
IsNotFound returns true if the error indicates a not-found condition
func IsRateLimited ¶
IsRateLimited returns true if the error indicates rate limiting
func IsUnavailable ¶
IsUnavailable returns true if the error indicates the database is unavailable
func IsValidationError ¶
IsValidationError returns true if the error is a validation error
Types ¶
type DatabaseError ¶
type DatabaseError struct {
OrigErr error // Original error from database driver
Op string // Operation being performed
Database string // Database system being used
Message string // Human-readable message
}
DatabaseError provides additional context for database related errors
func NewDatabaseError ¶
func NewDatabaseError(origErr error, database, op, msg string) *DatabaseError
NewDatabaseError creates a new database error
func (*DatabaseError) Error ¶
func (e *DatabaseError) Error() string
Error implements the error interface
func (*DatabaseError) Unwrap ¶
func (e *DatabaseError) Unwrap() error
Unwrap returns the original error for compatibility with errors.Is/As
type ReportParams ¶
type ReportParams struct {
Type ReportType
From time.Time
To time.Time
}
ReportParams holds parameters for generating reports
type ReportType ¶
type ReportType string
ReportType defines the type of report to generate
const ( // ReportTypeRedeemed represents a report of redeemed cocktails ReportTypeRedeemed ReportType = "redeemed" // ReportTypeAdded represents a report of added users ReportTypeAdded ReportType = "added" // ReportTypeAll represents a report of all users ReportTypeAll ReportType = "all" )
func ValidateReportType ¶
func ValidateReportType(reportType string) (ReportType, error)
ValidateReportType checks if the provided string is a valid report type
type Repository ¶
type Repository interface {
FindByEmail(ctx any, email string) (*User, error)
UpdateUser(ctx any, user *User) error
AddUser(ctx any, user *User) error
GetReport(ctx any, params ReportParams) ([]*User, error)
Close() error
}
Repository is the interface that all database implementations must satisfy
type User ¶
func (*User) IsRedeemed ¶
IsRedeemed returns true if the user has already redeemed their cocktail
type ValidationError ¶
type ValidationError struct {
Field string // Field that failed validation
Value string // Value that was invalid (may be omitted for privacy)
Message string // Human-readable error message
}
ValidationError represents errors related to input validation
func NewValidationError ¶
func NewValidationError(field, message string, value ...string) *ValidationError
NewValidationError creates a new validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface