domain

package
v1.0.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrorCode

func IsErrorCode(err error, code ErrorCode) bool

IsErrorCode checks if an error has a specific error code

Types

type DomainError

type DomainError struct {
	Code    ErrorCode
	Message string
	Details map[string]interface{}
	Err     error
}

DomainError represents a domain-specific error

func ErrBusinessRule

func ErrBusinessRule(rule string, violation string) *DomainError

ErrBusinessRule creates a business rule violation error

func ErrCSVExport added in v1.0.12

func ErrCSVExport(operation string, reason string) *DomainError

ErrCSVExport creates a CSV export error

func ErrCSVExportWithCause added in v1.0.12

func ErrCSVExportWithCause(operation string, reason string, err error) *DomainError

ErrCSVExportWithCause creates a CSV export error with cause

func ErrCalculation

func ErrCalculation(operation string, reason string) *DomainError

ErrCalculation creates a calculation error

func ErrCursorAPI

func ErrCursorAPI(operation string, statusCode int, response string) *DomainError

ErrCursorAPI creates a Cursor API error

func ErrCursorAPIWithCause

func ErrCursorAPIWithCause(operation string, err error) *DomainError

ErrCursorAPIWithCause creates a Cursor API error with cause

func ErrCursorDatabase

func ErrCursorDatabase(operation string, path string) *DomainError

ErrCursorDatabase creates a Cursor database error

func ErrCursorDatabaseWithCause

func ErrCursorDatabaseWithCause(operation string, path string, err error) *DomainError

ErrCursorDatabaseWithCause creates a Cursor database error with cause

func ErrCursorToken

func ErrCursorToken(reason string) *DomainError

ErrCursorToken creates a Cursor token error

func ErrCursorTokenWithCause

func ErrCursorTokenWithCause(reason string, err error) *DomainError

ErrCursorTokenWithCause creates a Cursor token error with cause

func ErrDataCollection added in v1.0.12

func ErrDataCollection(source string, reason string) *DomainError

ErrDataCollection creates a data collection error

func ErrDataCollectionWithCause added in v1.0.12

func ErrDataCollectionWithCause(source string, reason string, err error) *DomainError

ErrDataCollectionWithCause creates a data collection error with cause

func ErrFileOperation added in v1.0.12

func ErrFileOperation(operation string, path string, reason string) *DomainError

ErrFileOperation creates a file operation error

func ErrFileOperationWithCause added in v1.0.12

func ErrFileOperationWithCause(operation string, path string, err error) *DomainError

ErrFileOperationWithCause creates a file operation error with cause

func ErrFilePermission added in v1.0.12

func ErrFilePermission(path string, requiredPermission string) *DomainError

ErrFilePermission creates a file permission error

func ErrInvalidInput

func ErrInvalidInput(field string, reason string) *DomainError

ErrInvalidInput creates an invalid input error

func ErrInvalidState

func ErrInvalidState(entity string, currentState string, attemptedAction string) *DomainError

ErrInvalidState creates an invalid state error

func ErrNoDataAvailable added in v1.0.12

func ErrNoDataAvailable(source string, timeRange string) *DomainError

ErrNoDataAvailable creates a no data available error

func ErrNotFound

func ErrNotFound(resource string, id string) *DomainError

ErrNotFound creates a not found error

func ErrPathTraversal added in v1.0.12

func ErrPathTraversal(path string) *DomainError

ErrPathTraversal creates a path traversal error

func ErrRepository

func ErrRepository(operation string, err error) *DomainError

ErrRepository creates a repository error

func ErrSystemDirectory added in v1.0.12

func ErrSystemDirectory(path string) *DomainError

ErrSystemDirectory creates a system directory access error

func ErrTimezone

func ErrTimezone(operation string, reason string) *DomainError

ErrTimezone creates a timezone error

func ErrTimezoneDetection

func ErrTimezoneDetection(fallbackLocation string) *DomainError

ErrTimezoneDetection creates a timezone detection error

func ErrTimezoneParse

func ErrTimezoneParse(timezoneName string, err error) *DomainError

ErrTimezoneParse creates a timezone parsing error

func ErrTimezoneWithCause

func ErrTimezoneWithCause(operation string, reason string, err error) *DomainError

ErrTimezoneWithCause creates a timezone error with cause

func NewDomainError

func NewDomainError(code ErrorCode, message string) *DomainError

NewDomainError creates a new domain error

func NewDomainErrorWithCause

func NewDomainErrorWithCause(code ErrorCode, message string, err error) *DomainError

NewDomainErrorWithCause creates a new domain error with an underlying cause

func (*DomainError) Error

func (e *DomainError) Error() string

Error implements the error interface

func (*DomainError) Unwrap

func (e *DomainError) Unwrap() error

Unwrap returns the underlying error

func (*DomainError) WithDetails

func (e *DomainError) WithDetails(key string, value interface{}) *DomainError

WithDetails adds details to the error

type ErrorCode

type ErrorCode string

ErrorCode represents the type of domain error

const (
	// ErrCodeNotFound indicates that a requested resource was not found
	ErrCodeNotFound ErrorCode = "NOT_FOUND"

	// ErrCodeInvalidInput indicates that the input provided is invalid
	ErrCodeInvalidInput ErrorCode = "INVALID_INPUT"

	// ErrCodeBusinessRule indicates a business rule violation
	ErrCodeBusinessRule ErrorCode = "BUSINESS_RULE_VIOLATION"

	// ErrCodeCalculation indicates an error during calculation
	ErrCodeCalculation ErrorCode = "CALCULATION_ERROR"

	// ErrCodeRepository indicates a repository operation error
	ErrCodeRepository ErrorCode = "REPOSITORY_ERROR"

	// ErrCodeInvalidState indicates an invalid state transition
	ErrCodeInvalidState ErrorCode = "INVALID_STATE"

	// ErrCodeCursorToken indicates a Cursor token-related error
	ErrCodeCursorToken ErrorCode = "CURSOR_TOKEN_ERROR"

	// ErrCodeCursorAPI indicates a Cursor API communication error
	ErrCodeCursorAPI ErrorCode = "CURSOR_API_ERROR"

	// ErrCodeCursorDatabase indicates a Cursor database access error
	ErrCodeCursorDatabase ErrorCode = "CURSOR_DATABASE_ERROR"

	// ErrCodeTimezone indicates a timezone-related error
	ErrCodeTimezone ErrorCode = "TIMEZONE_ERROR"

	// ErrCodeCSVExport indicates a CSV export-related error
	ErrCodeCSVExport ErrorCode = "CSV_EXPORT_ERROR"

	// ErrCodeFileOperation indicates a file operation error
	ErrCodeFileOperation ErrorCode = "FILE_OPERATION_ERROR"

	// ErrCodeDataCollection indicates a data collection error
	ErrCodeDataCollection ErrorCode = "DATA_COLLECTION_ERROR"
)

func GetErrorCode

func GetErrorCode(err error) ErrorCode

GetErrorCode extracts the error code from an error

type Field

type Field struct {
	Key   string
	Value interface{}
}

func NewField

func NewField(key string, value interface{}) Field

type LogLevel

type LogLevel int
const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
)

type Logger

type Logger interface {
	Debug(ctx context.Context, msg string, fields ...Field)
	Info(ctx context.Context, msg string, fields ...Field)
	Warn(ctx context.Context, msg string, fields ...Field)
	Error(ctx context.Context, msg string, fields ...Field)

	WithFields(fields ...Field) Logger
}

type LoggerFactory

type LoggerFactory interface {
	CreateLogger(component string) Logger
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL