Documentation
¶
Index ¶
- func IsCircuitOpenError(err error) bool
- func IsConnectionError(err error) bool
- func IsNotFoundError(err error) bool
- func IsRetryExhaustedError(err error) bool
- func IsRetryableError(err error) bool
- func IsValidationError(err error) bool
- type CacheError
- func NewCacheError(errType ErrorType, key, message string, cause error) *CacheError
- func NewCacheErrorWithContext(errType ErrorType, key, message string, cause error, context *ErrorContext) *CacheError
- func NewCircuitOpenError(operation string) *CacheError
- func NewConnectionError(message string, cause error) *CacheError
- func NewKeyInvalidError(key, message string) *CacheError
- func NewNotFoundError(key string) *CacheError
- func NewRetryExhaustedError(operation string, attempts int, lastError error) *CacheError
- func NewSerializationError(key, message string, cause error) *CacheError
- func NewTimeoutError(key, message string, cause error) *CacheError
- func NewValidationError(message string, cause error) *CacheError
- func (e *CacheError) Error() string
- func (e *CacheError) GetRecoveryStrategy() RecoveryStrategy
- func (e *CacheError) Is(target error) bool
- func (e *CacheError) IsRetryable() bool
- func (e *CacheError) Unwrap() error
- func (e *CacheError) WithContext(operation string, attemptNumber int, duration time.Duration) *CacheError
- func (e *CacheError) WithMetadata(key string, value any) *CacheError
- type CircuitBreaker
- type CircuitBreakerConfig
- type CircuitBreakerState
- type Config
- type DefaultKeyGenerator
- func (kg *DefaultKeyGenerator) DiagramKey(diagramType models.DiagramType, name string) string
- func (kg *DefaultKeyGenerator) EntityKey(umlVersion, diagramName, entityID string) string
- func (kg *DefaultKeyGenerator) StateMachineKey(umlVersion, name string) string
- func (kg *DefaultKeyGenerator) ValidateKey(key string) error
- type ErrorContext
- type ErrorRecoveryManager
- func (erm *ErrorRecoveryManager) ExecuteWithRecovery(operation string, fn func() error) error
- func (erm *ErrorRecoveryManager) GetCircuitBreaker(operation string) *CircuitBreaker
- func (erm *ErrorRecoveryManager) GetCircuitBreakerMetrics() map[string]map[string]any
- func (erm *ErrorRecoveryManager) ShouldRetry(err error, operation string, attemptNumber int) (bool, time.Duration)
- type ErrorSeverity
- type ErrorType
- type InputValidator
- func (v *InputValidator) ValidateAndSanitizeContent(content, fieldName string) (string, error)
- func (v *InputValidator) ValidateAndSanitizeName(name, fieldName string) (string, error)
- func (v *InputValidator) ValidateAndSanitizeString(input, fieldName string) (string, error)
- func (v *InputValidator) ValidateAndSanitizeVersion(version, fieldName string) (string, error)
- func (v *InputValidator) ValidateCleanupPattern(pattern string) error
- func (v *InputValidator) ValidateContext(ctx context.Context) error
- func (v *InputValidator) ValidateEntityData(entity interface{}, fieldName string) error
- func (v *InputValidator) ValidateOperation(operation string) error
- func (v *InputValidator) ValidateTTL(ttl time.Duration, allowZero bool) error
- type KeyGenerator
- type RecoveryStrategy
- type RedisClient
- func (rc *RedisClient) Client() *redis.Client
- func (rc *RedisClient) Close() error
- func (rc *RedisClient) Config() *Config
- func (rc *RedisClient) DBSizeWithRetry(ctx context.Context) (int64, error)
- func (rc *RedisClient) DelBatchWithRetry(ctx context.Context, keys ...string) (int64, error)
- func (rc *RedisClient) DelWithRetry(ctx context.Context, keys ...string) error
- func (rc *RedisClient) ExistsWithRetry(ctx context.Context, keys ...string) (int64, error)
- func (rc *RedisClient) ExpireWithRetry(ctx context.Context, key string, expiration time.Duration) error
- func (rc *RedisClient) GetConnectionInfo(ctx context.Context) (map[string]interface{}, error)
- func (rc *RedisClient) GetWithRetry(ctx context.Context, key string) (string, error)
- func (rc *RedisClient) Health(ctx context.Context) error
- func (rc *RedisClient) HealthWithRetry(ctx context.Context) error
- func (rc *RedisClient) InfoWithRetry(ctx context.Context, section string) (string, error)
- func (rc *RedisClient) MemoryUsageWithRetry(ctx context.Context, key string) (int64, error)
- func (rc *RedisClient) PingWithRetry(ctx context.Context) error
- func (rc *RedisClient) ScanWithRetry(ctx context.Context, cursor uint64, match string, count int64) ([]string, uint64, error)
- func (rc *RedisClient) SetWithRetry(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- type RedisClientInterface
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCircuitOpenError ¶
IsCircuitOpenError checks if the error is a circuit open error
func IsConnectionError ¶
IsConnectionError checks if the error is a connection error
func IsNotFoundError ¶
IsNotFoundError checks if the error is a not found error
func IsRetryExhaustedError ¶
IsRetryExhaustedError checks if the error is a retry exhausted error
func IsRetryableError ¶
IsRetryableError checks if the error should trigger retry logic
func IsValidationError ¶
IsValidationError checks if the error is a validation error
Types ¶
type CacheError ¶
type CacheError struct { Type ErrorType `json:"type"` // Error type classification Key string `json:"key,omitempty"` // Cache key involved in the error Message string `json:"message"` // Human-readable error message Cause error `json:"-"` // Underlying error (not serialized) Context *ErrorContext `json:"context,omitempty"` // Additional error context Severity ErrorSeverity `json:"severity"` // Error severity level }
CacheError represents a cache-specific error with detailed context
func NewCacheError ¶
func NewCacheError(errType ErrorType, key, message string, cause error) *CacheError
NewCacheError creates a new CacheError with basic information
func NewCacheErrorWithContext ¶
func NewCacheErrorWithContext(errType ErrorType, key, message string, cause error, context *ErrorContext) *CacheError
NewCacheErrorWithContext creates a new CacheError with detailed context
func NewCircuitOpenError ¶
func NewCircuitOpenError(operation string) *CacheError
NewCircuitOpenError creates a circuit breaker open error
func NewConnectionError ¶
func NewConnectionError(message string, cause error) *CacheError
NewConnectionError creates a connection-specific cache error
func NewKeyInvalidError ¶
func NewKeyInvalidError(key, message string) *CacheError
NewKeyInvalidError creates a key validation error
func NewNotFoundError ¶
func NewNotFoundError(key string) *CacheError
NewNotFoundError creates a not found error
func NewRetryExhaustedError ¶
func NewRetryExhaustedError(operation string, attempts int, lastError error) *CacheError
NewRetryExhaustedError creates a retry exhausted error
func NewSerializationError ¶
func NewSerializationError(key, message string, cause error) *CacheError
NewSerializationError creates a serialization error
func NewTimeoutError ¶
func NewTimeoutError(key, message string, cause error) *CacheError
NewTimeoutError creates a timeout error
func NewValidationError ¶
func NewValidationError(message string, cause error) *CacheError
NewValidationError creates a validation error
func (*CacheError) GetRecoveryStrategy ¶
func (e *CacheError) GetRecoveryStrategy() RecoveryStrategy
GetRecoveryStrategy returns the recommended recovery strategy for this error
func (*CacheError) Is ¶
func (e *CacheError) Is(target error) bool
Is checks if the error matches the target error type
func (*CacheError) IsRetryable ¶
func (e *CacheError) IsRetryable() bool
IsRetryable returns true if this error should trigger retry logic
func (*CacheError) Unwrap ¶
func (e *CacheError) Unwrap() error
Unwrap returns the underlying cause error
func (*CacheError) WithContext ¶
func (e *CacheError) WithContext(operation string, attemptNumber int, duration time.Duration) *CacheError
WithContext adds context information to an existing CacheError
func (*CacheError) WithMetadata ¶
func (e *CacheError) WithMetadata(key string, value any) *CacheError
WithMetadata adds metadata to an existing CacheError
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern for error recovery
func NewCircuitBreaker ¶
func NewCircuitBreaker(config *CircuitBreakerConfig) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker with the given configuration
func (*CircuitBreaker) CanExecute ¶
func (cb *CircuitBreaker) CanExecute() error
CanExecute checks if the circuit breaker allows execution
func (*CircuitBreaker) GetMetrics ¶
func (cb *CircuitBreaker) GetMetrics() map[string]any
GetMetrics returns current circuit breaker metrics
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() CircuitBreakerState
GetState returns the current state of the circuit breaker
func (*CircuitBreaker) RecordFailure ¶
func (cb *CircuitBreaker) RecordFailure()
RecordFailure records a failed operation
func (*CircuitBreaker) RecordSuccess ¶
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess records a successful operation
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct { FailureThreshold int `json:"failure_threshold"` // Number of failures before opening RecoveryTimeout time.Duration `json:"recovery_timeout"` // Time to wait before trying half-open SuccessThreshold int `json:"success_threshold"` // Successes needed to close from half-open MaxHalfOpenCalls int `json:"max_half_open_calls"` // Max calls allowed in half-open state }
CircuitBreakerConfig defines circuit breaker behavior
func DefaultCircuitBreakerConfig ¶
func DefaultCircuitBreakerConfig() *CircuitBreakerConfig
DefaultCircuitBreakerConfig returns default circuit breaker configuration
type CircuitBreakerState ¶
type CircuitBreakerState int
CircuitBreakerState represents the state of a circuit breaker
const ( // CircuitBreakerClosed indicates normal operation CircuitBreakerClosed CircuitBreakerState = iota // CircuitBreakerOpen indicates circuit is open (failing fast) CircuitBreakerOpen // CircuitBreakerHalfOpen indicates circuit is testing if service recovered CircuitBreakerHalfOpen )
func (CircuitBreakerState) String ¶
func (s CircuitBreakerState) String() string
String returns the string representation of CircuitBreakerState
type Config ¶
type Config struct { // Redis connection settings RedisAddr string `json:"redis_addr"` // Redis server address (host:port) RedisPassword string `json:"redis_password"` // Redis password (optional) RedisDB int `json:"redis_db"` // Redis database number // Connection pool settings MaxRetries int `json:"max_retries"` // Maximum number of retries DialTimeout time.Duration `json:"dial_timeout"` // Timeout for establishing connection ReadTimeout time.Duration `json:"read_timeout"` // Timeout for socket reads WriteTimeout time.Duration `json:"write_timeout"` // Timeout for socket writes PoolSize int `json:"pool_size"` // Maximum number of socket connections // Cache settings DefaultTTL time.Duration `json:"default_ttl"` // Default time-to-live for cache entries // Resilience settings RetryConfig *RetryConfig `json:"retry_config"` // Retry configuration for operations }
Config holds Redis connection configuration parameters
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with sensible default values
type DefaultKeyGenerator ¶
type DefaultKeyGenerator struct{}
DefaultKeyGenerator implements the KeyGenerator interface
func (*DefaultKeyGenerator) DiagramKey ¶
func (kg *DefaultKeyGenerator) DiagramKey(diagramType models.DiagramType, name string) string
DiagramKey generates a cache key for PlantUML diagrams Format: /diagrams/<diagram_type>/<diagram_name>
func (*DefaultKeyGenerator) EntityKey ¶
func (kg *DefaultKeyGenerator) EntityKey(umlVersion, diagramName, entityID string) string
EntityKey generates a cache key for state machine entities Format: /machines/<uml_version>/<diagram_name>/entities/<entity_id>
func (*DefaultKeyGenerator) StateMachineKey ¶
func (kg *DefaultKeyGenerator) StateMachineKey(umlVersion, name string) string
StateMachineKey generates a cache key for parsed state machines Format: /machines/<uml_version>/<diagram_name>
func (*DefaultKeyGenerator) ValidateKey ¶
func (kg *DefaultKeyGenerator) ValidateKey(key string) error
ValidateKey validates that a cache key follows the expected format and constraints
type ErrorContext ¶
type ErrorContext struct { Operation string `json:"operation,omitempty"` // The operation that failed Timestamp time.Time `json:"timestamp"` // When the error occurred AttemptNumber int `json:"attempt_number,omitempty"` // Retry attempt number Duration time.Duration `json:"duration,omitempty"` // How long the operation took Metadata map[string]any `json:"metadata,omitempty"` // Additional context data }
ErrorContext provides additional context information for errors
type ErrorRecoveryManager ¶
type ErrorRecoveryManager struct {
// contains filtered or unexported fields
}
ErrorRecoveryManager manages error recovery strategies and circuit breakers
func NewErrorRecoveryManager ¶
func NewErrorRecoveryManager(config *CircuitBreakerConfig) *ErrorRecoveryManager
NewErrorRecoveryManager creates a new error recovery manager
func (*ErrorRecoveryManager) ExecuteWithRecovery ¶
func (erm *ErrorRecoveryManager) ExecuteWithRecovery(operation string, fn func() error) error
ExecuteWithRecovery executes an operation with error recovery mechanisms
func (*ErrorRecoveryManager) GetCircuitBreaker ¶
func (erm *ErrorRecoveryManager) GetCircuitBreaker(operation string) *CircuitBreaker
GetCircuitBreaker returns or creates a circuit breaker for the given operation
func (*ErrorRecoveryManager) GetCircuitBreakerMetrics ¶
func (erm *ErrorRecoveryManager) GetCircuitBreakerMetrics() map[string]map[string]any
GetCircuitBreakerMetrics returns metrics for all circuit breakers
func (*ErrorRecoveryManager) ShouldRetry ¶
func (erm *ErrorRecoveryManager) ShouldRetry(err error, operation string, attemptNumber int) (bool, time.Duration)
ShouldRetry determines if an operation should be retried based on the error and recovery strategy
type ErrorSeverity ¶
type ErrorSeverity int
ErrorSeverity represents the severity level of an error
const ( // SeverityLow indicates a low-severity error (e.g., validation, not found) SeverityLow ErrorSeverity = iota // SeverityMedium indicates a medium-severity error (e.g., serialization) SeverityMedium // SeverityHigh indicates a high-severity error (e.g., retry exhausted) SeverityHigh // SeverityCritical indicates a critical error (e.g., connection failure) SeverityCritical )
func GetErrorSeverity ¶
func GetErrorSeverity(err error) ErrorSeverity
GetErrorSeverity returns the severity level of an error
func (ErrorSeverity) String ¶
func (s ErrorSeverity) String() string
String returns the string representation of ErrorSeverity
type ErrorType ¶
type ErrorType int
ErrorType represents the type of cache error
const ( // ErrorTypeConnection indicates a Redis connection error ErrorTypeConnection ErrorType = iota // ErrorTypeKeyInvalid indicates an invalid cache key ErrorTypeKeyInvalid // ErrorTypeNotFound indicates a cache miss or key not found ErrorTypeNotFound // ErrorTypeSerialization indicates JSON marshaling/unmarshaling error ErrorTypeSerialization // ErrorTypeTimeout indicates a timeout during cache operation ErrorTypeTimeout // ErrorTypeCapacity indicates cache capacity or memory issues ErrorTypeCapacity // ErrorTypeValidation indicates input validation failure ErrorTypeValidation // ErrorTypeRetryExhausted indicates all retry attempts have been exhausted ErrorTypeRetryExhausted // ErrorTypeCircuitOpen indicates circuit breaker is open ErrorTypeCircuitOpen )
func (ErrorType) IsRetryable ¶
IsRetryable returns true if this error type should trigger retry logic
func (ErrorType) Severity ¶
func (e ErrorType) Severity() ErrorSeverity
Severity returns the severity level of the error type
type InputValidator ¶
type InputValidator struct {
// contains filtered or unexported fields
}
InputValidator provides comprehensive input validation and sanitization
func NewInputValidator ¶
func NewInputValidator() *InputValidator
NewInputValidator creates a new input validator with default settings
func (*InputValidator) ValidateAndSanitizeContent ¶
func (v *InputValidator) ValidateAndSanitizeContent(content, fieldName string) (string, error)
ValidateAndSanitizeContent validates and sanitizes content (PUML, JSON, etc.)
func (*InputValidator) ValidateAndSanitizeName ¶
func (v *InputValidator) ValidateAndSanitizeName(name, fieldName string) (string, error)
ValidateAndSanitizeName validates and sanitizes names (diagram names, entity IDs, etc.)
func (*InputValidator) ValidateAndSanitizeString ¶
func (v *InputValidator) ValidateAndSanitizeString(input, fieldName string) (string, error)
ValidateAndSanitizeString validates and sanitizes a general string input
func (*InputValidator) ValidateAndSanitizeVersion ¶
func (v *InputValidator) ValidateAndSanitizeVersion(version, fieldName string) (string, error)
ValidateAndSanitizeVersion validates and sanitizes version strings
func (*InputValidator) ValidateCleanupPattern ¶
func (v *InputValidator) ValidateCleanupPattern(pattern string) error
ValidateCleanupPattern validates cleanup patterns for security
func (*InputValidator) ValidateContext ¶
func (v *InputValidator) ValidateContext(ctx context.Context) error
ValidateContext validates context for timeout and cancellation
func (*InputValidator) ValidateEntityData ¶
func (v *InputValidator) ValidateEntityData(entity interface{}, fieldName string) error
ValidateEntityData validates entity data before storage
func (*InputValidator) ValidateOperation ¶
func (v *InputValidator) ValidateOperation(operation string) error
ValidateOperation validates operation strings for entity mapping
func (*InputValidator) ValidateTTL ¶
func (v *InputValidator) ValidateTTL(ttl time.Duration, allowZero bool) error
ValidateTTL validates time-to-live duration
type KeyGenerator ¶
type KeyGenerator interface { DiagramKey(diagramType models.DiagramType, name string) string StateMachineKey(umlVersion, name string) string EntityKey(umlVersion, diagramName, entityID string) string ValidateKey(key string) error }
KeyGenerator defines the interface for generating and validating cache keys
func NewKeyGenerator ¶
func NewKeyGenerator() KeyGenerator
NewKeyGenerator creates a new DefaultKeyGenerator instance
type RecoveryStrategy ¶
type RecoveryStrategy int
RecoveryStrategy represents different error recovery approaches
const ( // RecoveryStrategyFail indicates the error should not be recovered from RecoveryStrategyFail RecoveryStrategy = iota // RecoveryStrategyIgnore indicates the error can be safely ignored RecoveryStrategyIgnore // RecoveryStrategyRetryWithBackoff indicates retry with exponential backoff RecoveryStrategyRetryWithBackoff // RecoveryStrategyRetryWithDelay indicates retry with fixed delay RecoveryStrategyRetryWithDelay // RecoveryStrategyCircuitBreaker indicates circuit breaker should be activated RecoveryStrategyCircuitBreaker // RecoveryStrategyWaitAndRetry indicates wait for circuit breaker to close RecoveryStrategyWaitAndRetry )
func GetRecoveryStrategy ¶
func GetRecoveryStrategy(err error) RecoveryStrategy
GetRecoveryStrategy returns the recommended recovery strategy for an error
func (RecoveryStrategy) String ¶
func (r RecoveryStrategy) String() string
String returns the string representation of RecoveryStrategy
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
RedisClient wraps the go-redis client with additional functionality
func NewRedisClient ¶
func NewRedisClient(config *Config) (*RedisClient, error)
NewRedisClient creates a new Redis client with the provided configuration
func (*RedisClient) Client ¶
func (rc *RedisClient) Client() *redis.Client
Client returns the underlying Redis client for direct access
func (*RedisClient) Close ¶
func (rc *RedisClient) Close() error
Close closes the Redis client connection
func (*RedisClient) Config ¶
func (rc *RedisClient) Config() *Config
Config returns the Redis client configuration
func (*RedisClient) DBSizeWithRetry ¶
func (rc *RedisClient) DBSizeWithRetry(ctx context.Context) (int64, error)
DBSizeWithRetry performs a DBSIZE operation with retry logic
func (*RedisClient) DelBatchWithRetry ¶
DelBatchWithRetry performs a batch DEL operation with retry logic and returns count
func (*RedisClient) DelWithRetry ¶
func (rc *RedisClient) DelWithRetry(ctx context.Context, keys ...string) error
DelWithRetry performs a DEL operation with retry logic
func (*RedisClient) ExistsWithRetry ¶
ExistsWithRetry performs an EXISTS operation with retry logic
func (*RedisClient) ExpireWithRetry ¶
func (rc *RedisClient) ExpireWithRetry(ctx context.Context, key string, expiration time.Duration) error
ExpireWithRetry performs an EXPIRE operation with retry logic
func (*RedisClient) GetConnectionInfo ¶
func (rc *RedisClient) GetConnectionInfo(ctx context.Context) (map[string]interface{}, error)
GetConnectionInfo returns information about the current Redis connection
func (*RedisClient) GetWithRetry ¶
GetWithRetry performs a GET operation with retry logic
func (*RedisClient) Health ¶
func (rc *RedisClient) Health(ctx context.Context) error
Health performs a health check on the Redis connection
func (*RedisClient) HealthWithRetry ¶
func (rc *RedisClient) HealthWithRetry(ctx context.Context) error
HealthWithRetry performs a health check with retry logic
func (*RedisClient) InfoWithRetry ¶
InfoWithRetry performs an INFO operation with retry logic
func (*RedisClient) MemoryUsageWithRetry ¶
MemoryUsageWithRetry performs a MEMORY USAGE operation with retry logic
func (*RedisClient) PingWithRetry ¶
func (rc *RedisClient) PingWithRetry(ctx context.Context) error
PingWithRetry performs a ping operation with retry logic
func (*RedisClient) ScanWithRetry ¶
func (rc *RedisClient) ScanWithRetry(ctx context.Context, cursor uint64, match string, count int64) ([]string, uint64, error)
ScanWithRetry performs a SCAN operation with retry logic
func (*RedisClient) SetWithRetry ¶
func (rc *RedisClient) SetWithRetry(ctx context.Context, key string, value interface{}, expiration time.Duration) error
SetWithRetry performs a SET operation with retry logic
type RedisClientInterface ¶
type RedisClientInterface interface { Health(ctx context.Context) error HealthWithRetry(ctx context.Context) error SetWithRetry(ctx context.Context, key string, value interface{}, expiration time.Duration) error GetWithRetry(ctx context.Context, key string) (string, error) DelWithRetry(ctx context.Context, keys ...string) error ExistsWithRetry(ctx context.Context, keys ...string) (int64, error) // Enhanced cleanup and monitoring methods ScanWithRetry(ctx context.Context, cursor uint64, match string, count int64) ([]string, uint64, error) DelBatchWithRetry(ctx context.Context, keys ...string) (int64, error) DBSizeWithRetry(ctx context.Context) (int64, error) InfoWithRetry(ctx context.Context, section string) (string, error) MemoryUsageWithRetry(ctx context.Context, key string) (int64, error) Client() *redis.Client Config() *Config Close() error }
RedisClientInterface defines the interface for Redis client operations
type RetryConfig ¶
type RetryConfig struct { MaxAttempts int `json:"max_attempts"` // Maximum number of retry attempts InitialDelay time.Duration `json:"initial_delay"` // Initial delay before first retry MaxDelay time.Duration `json:"max_delay"` // Maximum delay between retries Multiplier float64 `json:"multiplier"` // Backoff multiplier Jitter bool `json:"jitter"` // Whether to add random jitter RetryableOps []string `json:"retryable_ops"` // Operations that should be retried }
RetryConfig defines retry behavior with exponential backoff
func DefaultRetryConfig ¶
func DefaultRetryConfig() *RetryConfig
DefaultRetryConfig returns a RetryConfig with sensible default values
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
error_handling_example
command
|
|
redis_client_example
command
|
|
retry_example
command
|