health

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	Name   string
	Health ComponentHealth
	Error  error
}

CheckResult representa el resultado de un health check individual

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker agregado que combina múltiples health checkers

func NewChecker

func NewChecker(service, version string, opts ...CheckerOption) *Checker

NewChecker crea un nuevo health checker agregado

func (*Checker) AddChecker

func (c *Checker) AddChecker(checker HealthChecker)

AddChecker añade un health checker

func (*Checker) Check

func (c *Checker) Check(ctx context.Context) HealthResponse

Check ejecuta todos los health checks

func (*Checker) GetComponentStatus

func (c *Checker) GetComponentStatus(ctx context.Context, componentName string) (ComponentHealth, bool)

GetComponentStatus obtiene el estado de un componente específico

func (*Checker) GetServiceInfo

func (c *Checker) GetServiceInfo() map[string]interface{}

GetServiceInfo retorna información básica del servicio

func (*Checker) IsHealthy

func (c *Checker) IsHealthy(ctx context.Context) bool

IsHealthy verifica si el servicio está saludable

func (*Checker) IsLive

func (c *Checker) IsLive(ctx context.Context) bool

IsLive verifica si el servicio está vivo (liveness probe)

func (*Checker) IsReady

func (c *Checker) IsReady(ctx context.Context) bool

IsReady verifica si el servicio está listo (readiness probe)

func (*Checker) ListComponents

func (c *Checker) ListComponents() []string

ListComponents retorna la lista de nombres de componentes

type CheckerOption

type CheckerOption func(*Checker)

CheckerOption define opciones para configurar el Checker

func WithBuildInfo

func WithBuildInfo(buildTime, gitCommit string) CheckerOption

WithBuildInfo configura información de build

func WithEnvironment

func WithEnvironment(env string) CheckerOption

WithEnvironment configura el environment

type ComponentHealth

type ComponentHealth struct {
	Status      Status                 `json:"status"`
	Message     string                 `json:"message,omitempty"`
	Timestamp   time.Time              `json:"timestamp"`
	Duration    time.Duration          `json:"duration"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
	Error       string                 `json:"error,omitempty"`
	LastChecked time.Time              `json:"last_checked"`
}

ComponentHealth representa la salud de un componente individual

func NewComponentHealth

func NewComponentHealth(status Status, message string) ComponentHealth

NewComponentHealth crea un nuevo ComponentHealth

func (ComponentHealth) WithDuration

func (c ComponentHealth) WithDuration(duration time.Duration) ComponentHealth

WithDuration añade duración al ComponentHealth

func (ComponentHealth) WithError

func (c ComponentHealth) WithError(err error) ComponentHealth

WithError añade un error al ComponentHealth

func (ComponentHealth) WithMetadata

func (c ComponentHealth) WithMetadata(key string, value interface{}) ComponentHealth

WithMetadata añade metadata al ComponentHealth

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler maneja las rutas de health check

func NewHandler

func NewHandler(checker *Checker, timeout time.Duration) *Handler

NewHandler crea un nuevo handler de health checks

func (*Handler) Component

func (h *Handler) Component(c *gin.Context)

Component maneja GET /health/component/{name} - health check de componente específico

func (*Handler) Components

func (h *Handler) Components(c *gin.Context)

Components maneja GET /health/components - lista todos los componentes

func (*Handler) Health

func (h *Handler) Health(c *gin.Context)

Health maneja GET /health - health check completo

func (*Handler) Info

func (h *Handler) Info(c *gin.Context)

Info maneja GET /health/info - información del servicio

func (*Handler) Liveness

func (h *Handler) Liveness(c *gin.Context)

Liveness maneja GET /health/live - liveness probe

func (*Handler) Middleware

func (h *Handler) Middleware() gin.HandlerFunc

Middleware crea un middleware que registra health check requests

func (*Handler) Readiness

func (h *Handler) Readiness(c *gin.Context)

Readiness maneja GET /health/ready - readiness probe

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(router gin.IRouter)

RegisterRoutes registra todas las rutas de health check en un router Gin

type HealthChecker

type HealthChecker interface {
	// Name retorna el nombre del componente
	Name() string

	// Check ejecuta el health check
	Check(ctx context.Context) ComponentHealth

	// IsRequired indica si este componente es requerido para la salud general
	IsRequired() bool

	// Timeout retorna el timeout para este health check
	Timeout() time.Duration
}

HealthChecker define la interfaz para health checkers

type HealthResponse

type HealthResponse struct {
	Status      Status                     `json:"status"`
	Service     string                     `json:"service"`
	Version     string                     `json:"version"`
	Timestamp   time.Time                  `json:"timestamp"`
	Uptime      time.Duration              `json:"uptime"`
	Components  map[string]ComponentHealth `json:"components"`
	SystemInfo  SystemInfo                 `json:"system_info"`
	RequestID   string                     `json:"request_id,omitempty"`
	Environment string                     `json:"environment,omitempty"`
}

HealthResponse representa la respuesta completa de health check

type Status

type Status string

Status representa el estado de salud de un componente

const (
	StatusHealthy   Status = "healthy"
	StatusUnhealthy Status = "unhealthy"
	StatusDegraded  Status = "degraded"
	StatusUnknown   Status = "unknown"
)

func OverallStatus

func OverallStatus(components map[string]ComponentHealth) Status

OverallStatus calcula el estado general basado en los componentes

type SystemInfo

type SystemInfo struct {
	Version     string    `json:"version"`
	BuildTime   string    `json:"build_time,omitempty"`
	GitCommit   string    `json:"git_commit,omitempty"`
	GoVersion   string    `json:"go_version"`
	Platform    string    `json:"platform"`
	StartTime   time.Time `json:"start_time"`
	Uptime      string    `json:"uptime"`
	Environment string    `json:"environment,omitempty"`
}

SystemInfo representa información del sistema

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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