Documentation
¶
Index ¶
- func Debug(message string, fields ...map[string]interface{})
- func Debugf(format string, args ...interface{})
- func Error(message string, fields ...map[string]interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(message string, fields ...map[string]interface{})
- func Fatalf(format string, args ...interface{})
- func HealthHandler(monitor *HealthMonitor) http.HandlerFunc
- func Info(message string, fields ...map[string]interface{})
- func Infof(format string, args ...interface{})
- func LivenessHandler() http.HandlerFunc
- func MetricsHandler(registry *MetricRegistry) http.HandlerFunc
- func MetricsMiddleware(metrics *ApplicationMetrics, logger *Logger) func(next http.Handler) http.Handler
- func ReadinessHandler() http.HandlerFunc
- func RecoveryMiddleware(logger *Logger) func(next http.Handler) http.Handler
- func SetDefaultLogger(logger *Logger)
- func StructuredLoggingMiddleware(logger *Logger) func(next http.Handler) http.Handler
- func ToContext(ctx context.Context, logger *Logger) context.Context
- func Trace(message string, fields ...map[string]interface{})
- func Tracef(format string, args ...interface{})
- func Warn(message string, fields ...map[string]interface{})
- func Warnf(format string, args ...interface{})
- type ApplicationMetrics
- type Config
- type Counter
- type Gauge
- func (g *Gauge) Add(delta int64)
- func (g *Gauge) Dec()
- func (g *Gauge) Get() int64
- func (g *Gauge) Inc()
- func (g *Gauge) Labels() map[string]string
- func (g *Gauge) Name() string
- func (g *Gauge) Set(value int64)
- func (g *Gauge) Sub(delta int64)
- func (g *Gauge) Type() MetricType
- func (g *Gauge) Value() interface{}
- type HealthCheck
- type HealthChecker
- type HealthMonitor
- type HealthStatus
- type Histogram
- type LogEntry
- type LogLevel
- type Logger
- func (l *Logger) Debug(message string, fields ...map[string]interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(message string, fields ...map[string]interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(message string, fields ...map[string]interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) GetLevel() LogLevel
- func (l *Logger) Info(message string, fields ...map[string]interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) Trace(message string, fields ...map[string]interface{})
- func (l *Logger) Tracef(format string, args ...interface{})
- func (l *Logger) Warn(message string, fields ...map[string]interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WithField(key string, value interface{}) *Logger
- func (l *Logger) WithFields(fields map[string]interface{}) *Logger
- func (l *Logger) WithRequestID(requestID string) *Logger
- func (l *Logger) WithUserID(userID string) *Logger
- type Metric
- type MetricRegistry
- type MetricType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a formatted debug message using the default logger
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a formatted error message using the default logger
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs a formatted fatal message using the default logger and exits
func HealthHandler ¶
func HealthHandler(monitor *HealthMonitor) http.HandlerFunc
HealthHandler returns an HTTP handler for health endpoint
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a formatted info message using the default logger
func LivenessHandler ¶
func LivenessHandler() http.HandlerFunc
LivenessHandler returns an HTTP handler for liveness endpoint
func MetricsHandler ¶
func MetricsHandler(registry *MetricRegistry) http.HandlerFunc
MetricsHandler returns an HTTP handler for metrics endpoint
func MetricsMiddleware ¶
func MetricsMiddleware(metrics *ApplicationMetrics, logger *Logger) func(next http.Handler) http.Handler
MetricsMiddleware creates middleware that automatically tracks HTTP metrics
func ReadinessHandler ¶
func ReadinessHandler() http.HandlerFunc
ReadinessHandler returns an HTTP handler for readiness endpoint
func RecoveryMiddleware ¶
RecoveryMiddleware creates structured logging recovery middleware
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
SetDefaultLogger sets the global default logger
func StructuredLoggingMiddleware ¶
StructuredLoggingMiddleware creates middleware that adds structured logger to request context
func Tracef ¶
func Tracef(format string, args ...interface{})
Tracef logs a formatted trace message using the default logger
Types ¶
type ApplicationMetrics ¶
type ApplicationMetrics struct {
RequestsTotal *Counter
RequestDuration *Histogram
ResponseStatusCodes *Counter
ActiveConnections *Gauge
ErrorsTotal *Counter
}
ApplicationMetrics holds commonly used application metrics
func NewApplicationMetrics ¶
func NewApplicationMetrics() *ApplicationMetrics
NewApplicationMetrics creates application metrics
func (*ApplicationMetrics) Register ¶
func (am *ApplicationMetrics) Register(registry *MetricRegistry)
Register registers all application metrics
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter represents a counter metric
func NewCounter ¶
NewCounter creates a new counter
func (*Counter) Type ¶
func (c *Counter) Type() MetricType
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge represents a gauge metric
func (*Gauge) Type ¶
func (g *Gauge) Type() MetricType
type HealthCheck ¶
type HealthCheck struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
Details interface{} `json:"details,omitempty"`
}
HealthCheck represents an individual health check
type HealthChecker ¶
type HealthChecker func() HealthCheck
HealthChecker function type for health checks
func DatabaseHealthChecker ¶
func DatabaseHealthChecker(pingFunc func() error) HealthChecker
DatabaseHealthChecker creates a health checker for database connectivity
func FileSystemHealthChecker ¶
func FileSystemHealthChecker(path string) HealthChecker
FileSystemHealthChecker creates a health checker for file system access
func RedisHealthChecker ¶
func RedisHealthChecker(pingFunc func() error) HealthChecker
RedisHealthChecker creates a health checker for Redis connectivity
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
HealthMonitor manages health checks
func GetDefaultHealthMonitor ¶
func GetDefaultHealthMonitor() *HealthMonitor
GetDefaultHealthMonitor returns the default health monitor
func NewHealthMonitor ¶
func NewHealthMonitor(version string) *HealthMonitor
NewHealthMonitor creates a new health monitor
func (*HealthMonitor) AddCheck ¶
func (hm *HealthMonitor) AddCheck(name string, checker HealthChecker)
AddCheck adds a health check
func (*HealthMonitor) CheckHealth ¶
func (hm *HealthMonitor) CheckHealth() HealthStatus
CheckHealth performs all health checks
func (*HealthMonitor) RemoveCheck ¶
func (hm *HealthMonitor) RemoveCheck(name string)
RemoveCheck removes a health check
type HealthStatus ¶
type HealthStatus struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
Version string `json:"version,omitempty"`
Uptime string `json:"uptime"`
Checks map[string]HealthCheck `json:"checks,omitempty"`
}
HealthStatus represents the health status of the application
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
Histogram represents a histogram metric
func NewHistogram ¶
NewHistogram creates a new histogram with default buckets
func NewHistogramWithBuckets ¶
NewHistogramWithBuckets creates a new histogram with custom buckets
func (*Histogram) Type ¶
func (h *Histogram) Type() MetricType
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
Fields map[string]interface{} `json:"fields,omitempty"`
Caller string `json:"caller,omitempty"`
RequestID string `json:"request_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Service string `json:"service,omitempty"`
}
LogEntry represents a structured log entry
type LogLevel ¶
type LogLevel int
LogLevel represents the severity of a log entry
func ParseLogLevel ¶
ParseLogLevel converts a string to LogLevel
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a structured logger
func FromContext ¶
FromContext retrieves a logger from context or returns the default logger
func GetDefaultLogger ¶
func GetDefaultLogger() *Logger
GetDefaultLogger returns the global default logger
func (*Logger) WithFields ¶
WithFields returns a new logger with additional fields
func (*Logger) WithRequestID ¶
WithRequestID returns a new logger with request ID
func (*Logger) WithUserID ¶
WithUserID returns a new logger with user ID
type Metric ¶
type Metric interface {
Type() MetricType
Name() string
Value() interface{}
Labels() map[string]string
}
Metric represents a metric
type MetricRegistry ¶
type MetricRegistry struct {
// contains filtered or unexported fields
}
MetricRegistry manages metrics
func GetDefaultRegistry ¶
func GetDefaultRegistry() *MetricRegistry
GetDefaultRegistry returns the default metric registry
func NewMetricRegistry ¶
func NewMetricRegistry() *MetricRegistry
NewMetricRegistry creates a new metric registry
func (*MetricRegistry) Get ¶
func (r *MetricRegistry) Get(name string) (Metric, bool)
Get retrieves a metric by name
func (*MetricRegistry) GetAll ¶
func (r *MetricRegistry) GetAll() map[string]Metric
GetAll returns all metrics
func (*MetricRegistry) Register ¶
func (r *MetricRegistry) Register(metric Metric)
Register registers a metric
func (*MetricRegistry) Unregister ¶
func (r *MetricRegistry) Unregister(name string)
Unregister removes a metric
type MetricType ¶
type MetricType string
MetricType represents the type of metric
const ( CounterType MetricType = "counter" GaugeType MetricType = "gauge" HistogramType MetricType = "histogram" )