Documentation
¶
Index ¶
- func CustomRecoveryMiddleware(logger *logrus.Logger, handler func(c *gin.Context, err interface{})) gin.HandlerFunc
- func PanicBadRequest(message string, details interface{})
- func PanicConflict(message string, details interface{})
- func PanicForbidden(message string, details interface{})
- func PanicInternalError(message string, details interface{})
- func PanicNotFound(message string, details interface{})
- func PanicUnauthorized(message string, details interface{})
- func PanicWithHTTPError(statusCode int, message string, details interface{})
- func RecoveryMiddleware(logger *logrus.Logger, config *RecoveryConfig) gin.HandlerFunc
- func RecoveryWithStatsMiddleware(logger *logrus.Logger, collector *RecoveryStatsCollector, ...) gin.HandlerFunc
- func SecureRecoveryMiddleware(logger *logrus.Logger) gin.HandlerFunc
- type HTTPError
- type PanicInfo
- type RecoveryConfig
- type RecoveryStats
- type RecoveryStatsCollector
- type RequestInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CustomRecoveryMiddleware ¶
func CustomRecoveryMiddleware(logger *logrus.Logger, handler func(c *gin.Context, err interface{})) gin.HandlerFunc
CustomRecoveryMiddleware middleware de recovery con handler personalizado
func PanicBadRequest ¶
func PanicBadRequest(message string, details interface{})
Common panic helpers
func PanicConflict ¶
func PanicConflict(message string, details interface{})
func PanicForbidden ¶
func PanicForbidden(message string, details interface{})
func PanicInternalError ¶
func PanicInternalError(message string, details interface{})
func PanicNotFound ¶
func PanicNotFound(message string, details interface{})
func PanicUnauthorized ¶
func PanicUnauthorized(message string, details interface{})
func PanicWithHTTPError ¶
PanicHandler función helper para hacer panic con HTTPError
func RecoveryMiddleware ¶
func RecoveryMiddleware(logger *logrus.Logger, config *RecoveryConfig) gin.HandlerFunc
RecoveryMiddleware middleware para recuperación de panics
func RecoveryWithStatsMiddleware ¶
func RecoveryWithStatsMiddleware(logger *logrus.Logger, collector *RecoveryStatsCollector, config *RecoveryConfig) gin.HandlerFunc
RecoveryWithStatsMiddleware middleware de recovery que recolecta estadísticas
func SecureRecoveryMiddleware ¶
func SecureRecoveryMiddleware(logger *logrus.Logger) gin.HandlerFunc
SecureRecoveryMiddleware middleware de recovery que no expone información sensible
Types ¶
type HTTPError ¶
HTTPError representa un error HTTP con código de estado específico
func NewHTTPError ¶
NewHTTPError crea un nuevo HTTPError
type PanicInfo ¶
type PanicInfo struct {
Error interface{} `json:"error"`
Stack string `json:"stack,omitempty"`
RequestInfo *RequestInfo `json:"request_info,omitempty"`
Timestamp time.Time `json:"timestamp"`
CorrelationID string `json:"correlation_id,omitempty"`
RequestID string `json:"request_id,omitempty"`
}
PanicInfo información sobre el panic
type RecoveryConfig ¶
type RecoveryConfig struct {
// Stack trace settings
EnableStackTrace bool
StackSize int
SkipFrames int
// Response settings
EnableDetailedError bool
CustomErrorMessage string
// Logging settings
LogLevel logrus.Level
LogStackTrace bool
// Callbacks
OnPanic func(c *gin.Context, err interface{})
OnRecovery func(c *gin.Context, err interface{}, stack []byte)
// Security settings
SanitizeResponse bool
IncludeRequestInfo bool
}
RecoveryConfig configuración del middleware de recovery
func DefaultRecoveryConfig ¶
func DefaultRecoveryConfig() *RecoveryConfig
DefaultRecoveryConfig retorna configuración por defecto
type RecoveryStats ¶
type RecoveryStats struct {
TotalPanics int64 `json:"total_panics"`
PanicsByType map[string]int64 `json:"panics_by_type"`
PanicsByPath map[string]int64 `json:"panics_by_path"`
LastPanic time.Time `json:"last_panic"`
RecentPanics []PanicInfo `json:"recent_panics"`
}
RecoveryStats estadísticas de recovery
type RecoveryStatsCollector ¶
type RecoveryStatsCollector struct {
// contains filtered or unexported fields
}
RecoveryStatsCollector recolecta estadísticas de recovery
func NewRecoveryStatsCollector ¶
func NewRecoveryStatsCollector() *RecoveryStatsCollector
NewRecoveryStatsCollector crea un nuevo recolector de estadísticas
func (*RecoveryStatsCollector) GetStats ¶
func (rsc *RecoveryStatsCollector) GetStats() RecoveryStats
GetStats retorna las estadísticas actuales
func (*RecoveryStatsCollector) RecordPanic ¶
func (rsc *RecoveryStatsCollector) RecordPanic(panicInfo *PanicInfo)
RecordPanic registra un panic
type RequestInfo ¶
type RequestInfo struct {
Method string `json:"method"`
Path string `json:"path"`
Query string `json:"query,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
ClientIP string `json:"client_ip"`
Headers map[string]string `json:"headers,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
UserID string `json:"user_id,omitempty"`
}
RequestInfo información de la request que causó el panic